基于以下内容来describe the model selection prcedure that you adopted并且report and discuss the estimation result based on training set of each candidate model::from sklearn.model_selection import train_test_split X_tv, X_test, y_tv, y_test = train_test_split(X,y, test_size=0.2, random_state=1 ) X_tra, X_val, y_tra, y_val = train_test_split(X_tv,y_tv, test_size=0.25, random_state=1 ) # setting features F1=["Panel_Capacity"] F2=["Panel_Capacity","Roof_Azimuth","Latitude","Roof_Pitch","Shading_Partial","Shading_Significant"] F3=["Panel_Capacity","Roof_Azimuth","Latitude","Roof_Pitch","Shading_Partial","Shading_Significant","Shading","Year","City_Melbourne","City_Sydney","Shading*Panel_Capacity"] x1_tra=X_tra[F1].to_numpy().reshape(-1,1) y1_tra=y_tra from sklearn.linear_model import LinearRegression from sklearn.metrics import mean_squared_error as mse # model estimation by using training set M1=LinearRegression() M1.fit(x1_tra,y1_tra) # coefficients print(M1.intercept_) print(M1.coef_) x2_tra=X_tra[F2].to_numpy() y2_tra=y_tra # model estimation by using training set M2=LinearRegression() M2.fit(x2_tra,y2_tra) # coefficients print(M2.intercept_) print(M2.coef_) # model selection by using validation set x2_val=X_val[F2].to_numpy() M2_pre=M2.predict(x2_val)
时间: 2023-07-15 14:09:57 浏览: 63
The model selection procedure adopted in this code involves splitting the data into training, validation, and testing sets. The training set is used to fit the models, the validation set is used to select the best model, and the testing set is used to evaluate the performance of the final model.
The data is split using the train_test_split function from the sklearn.model_selection module. The test_size parameter is set to 0.2, which means that the testing set will contain 20% of the data. The random_state parameter is set to 1 to ensure reproducibility.
The training set is further split into a training subset and a validation subset using the same function. The test_size parameter is set to 0.25, which means that the validation set will contain 25% of the training set. Again, the random_state parameter is set to 1 for reproducibility.
Three sets of features are defined: F1, F2, and F3. F1 contains only the "Panel_Capacity" feature, F2 contains "Panel_Capacity", "Roof_Azimuth", "Latitude", "Roof_Pitch", "Shading_Partial", and "Shading_Significant" features, and F3 contains all the features in F2 plus "Shading", "Year", "City_Melbourne", "City_Sydney", and "Shading*Panel_Capacity".
For each set of features, a linear regression model is estimated using the training set. The mean squared error is used as the evaluation metric, calculated using the mean_squared_error function from the sklearn.metrics module.
After estimation, the intercept and coefficients of each model are printed.
The second model (M2) is selected as the best model based on its performance on the validation set. The features in F2 were used to fit the model, and the predictions on the validation set were made using the predict method of the M2 object. The predictions are stored in the M2_pre variable.
No further analysis or discussion of the estimation results is provided in the code. However, one could compare the performance of M2 to that of M1 and M3 using the mean squared error on the testing set. Alternatively, one could perform a more thorough evaluation of the models, such as examining their residuals and checking for violations of assumptions.