Skip to content

Commit 25552a1

Browse files
committed
Gradient boosting regressor
1 parent 74c8cd3 commit 25552a1

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

machine_learning/Gradient-boosting-regressor.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,33 @@
1313

1414
def main():
1515

16-
# loading the dataset from the sklearn package
16+
# loading the dataset from the sklearn
1717
df = load_boston()
1818
print(df.keys())
19-
# now let construct a data frame with data and target variables
19+
# now let construct a data frame
2020
df_boston = pd.DataFrame(df.data, columns=df.feature_names)
2121
# let add the target to the dataframe
2222
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
2424
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
2728

2829
X = df_boston.iloc[:, :-1]
2930
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.
3132
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+
)
3335

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+
)
3639
# training the model
3740
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"""
3943
score = model.score(X_train, y_train).round(3)
4044
print("Training score of GradientBoosting is :", score)
4145
print(

0 commit comments

Comments
 (0)