# Vorlesung – Multiple Linear Regression – Jason

0
25

Die Methode „A number of Linear Regression“ (A number of Linear Regression) und „Python“ ist die Lösung.

`import pandas as pdimport numpy as npfrom sklearn.linear_model import LinearRegressionfrom sklearn.model_selection import KFoldimport statsmodels.api as smInformation = {'Temperature':[26,25,20,23,28,28,29,30,28,35,36,33,29,27,30,33,22,20,19,22,23,29,30,33,28,33,31,38,26,22],'humidity':[48,55,60,43,59,57,60,67,78,63,67,82,64,70,72,89,51,45,45,66,43,73,62,56,52,57,44,71,42,60],'NumberOfPeople':[300,421,321,400,511,672,561,555,712,918,921,1001,883,912,991,850,704,632,499,611,502,539,601,732,602,791,910,831,513,600],'Income':[3000,2000,2150,1500,5500,6000,5123,6010,6648,7001,7214,7101,6812,5651,6468,7510,4031,3984,1594,4010,3151,5413,6641,6847,7000,6413,7300,7701,3101,3100],}df = pd.DataFrame(Information)df`

Die Verwendung von Sklearn in Python, die Verwendung von LinearRegression() und die Verwendung von LinearRegression() sind nicht möglich.差異僅在於自變項從一個變成多個而已,所以實作上會Antwort:

`x = df.iloc[:,0:3].valuesy = df.iloc[:,3].valuesmannequin = LinearRegression()mannequin.match(x,y)`

`#使用KFold進行交叉驗證CrossVal = KFold(n_splits=10, shuffle=True)ScoreList = []for train_index, test_index in CrossVal.break up(x,y):x_train, x_test = x[train_index], x[test_index]y_train, y_test = y[train_index], y[test_index]mannequin.match(x_train, y_train)R_Square = mannequin.rating(x_test, y_test)ScoreList.append(R_Square)#print出所有的分數print(R_Square)#查看分數的標準差np.std(ScoreList)`

`import statsmodels.api as smx = sm.add_constant(x)Statistic = sm.OLS(y,x).match()Statistic.abstract()`