|
13 | 13 |
|
14 | 14 | def main():
|
15 | 15 |
|
16 |
| - # loading the dataset from the sklearn package |
| 16 | + # loading the dataset from the sklearn |
17 | 17 | df = load_boston()
|
18 | 18 | print(df.keys())
|
19 |
| - # now let construct a data frame with data and target variables |
| 19 | + # now let construct a data frame |
20 | 20 | df_boston = pd.DataFrame(df.data, columns=df.feature_names)
|
21 | 21 | # let add the target to the dataframe
|
22 | 22 | df_boston["Price"] = df.target
|
23 |
| - # let us print the first five rows using the head function |
| 23 | + # print the first five rows using the head function |
24 | 24 | print(df_boston.head())
|
25 |
| - print(df_boston.describe().T) # to see summary statistics of the dataset |
26 |
| - # Feature selection means for independent and dependent variables |
| 25 | + # Summary statistics |
| 26 | + print(df_boston.describe().T) |
| 27 | + # Feature selection |
27 | 28 |
|
28 | 29 | X = df_boston.iloc[:, :-1]
|
29 | 30 | y = df_boston.iloc[:, -1] # target variable
|
30 |
| - # we are going to split the data with 75% train and 25% test sets. |
| 31 | + # split the data with 75% train and 25% test sets. |
31 | 32 | X_train, X_test, y_train, y_test = train_test_split(
|
32 |
| - X, y, random_state=0, test_size=0.25) |
| 33 | + X, y, random_state=0, test_size=0.25 |
| 34 | + ) |
33 | 35 |
|
34 |
| - model = GradientBoostingRegressor(n_estimators = 500, |
35 |
| - max_depth =5,min_samples_split=4,learning_rate=0.01 ) |
| 36 | + model = GradientBoostingRegressor( |
| 37 | + n_estimators=500, max_depth=5, min_samples_split=4, learning_rate=0.01 |
| 38 | + ) |
36 | 39 | # training the model
|
37 | 40 | model.fit(X_train, y_train)
|
38 |
| - """let have a look on the train and test score to see how good the model fit the data""" |
| 41 | + """let have a look on the train and test score |
| 42 | + to see how good the model fit the data""" |
39 | 43 | score = model.score(X_train, y_train).round(3)
|
40 | 44 | print("Training score of GradientBoosting is :", score)
|
41 | 45 | print(
|
|
0 commit comments