Skip to content

Commit 54827b6

Browse files
committed
Gradient boosting regressor implementation
1 parent 2b15386 commit 54827b6

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

machine_learning/Gradient-boosting-regressor.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
#!/usr/bin/env python
2-
# coding: utf-8
3-
4-
# In[17]:
5-
6-
71
"""Implementation of GradientBoostingRegressor in sklearn using the
82
boston dataset which is very popular for regression problem to
93
predict house price.
@@ -19,19 +13,19 @@ def main():
1913
# loading the dataset from the sklearn package
2014
df = load_boston()
2115
print(df.keys())
22-
# now let constract a data frame with data and target variables
16+
# now let construct a data frame with data and target variables
2317
df_boston = pd.DataFrame(df.data,columns =df.feature_names)
2418
# let add the target to the dataframe
2519
df_boston['Price']= df.target
2620
# let us print the first five rows using the head function
2721
print(df_boston.head())
2822
print(df_boston.describe().T) # to see summary statistics of the dataset
29-
# Feature selection means for independant and dependent variables
23+
# Feature selection means for independent and dependent variables
3024
X = df_boston.iloc[:,:-1]
3125
y = df_boston.iloc[:,-1] # target variable
3226
# we are going to split the data with 75% train and 25% test sets.
3327
X_train,X_test,y_train,y_test = train_test_split(X,y,random_state = 0, test_size = .25)
34-
# now let set the parametes of our model
28+
# now let set the parameters of the model
3529
params = {'n_estimators': 500, 'max_depth': 5, 'min_samples_split': 4,
3630
'learning_rate': 0.01, 'loss': 'ls'}
3731
model = GradientBoostingRegressor(**params)
@@ -56,7 +50,7 @@ def main():
5650
ax.set_xlabel('Actual')
5751
ax.set_ylabel('Predicted')
5852
ax.set_title("Truth vs Predicted")
59-
# this show function will display the ploting
53+
# this show function will display the plotting
6054
plt.show()
6155

6256

0 commit comments

Comments
 (0)