Skip to content

Commit 98ac63c

Browse files
authored
Linear Regressor
1 parent 11957e4 commit 98ac63c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Diff for: 27.XGBRegressor.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import numpy as np
2+
import pandas as pd
3+
import xgboost as xg
4+
from sklearn.model_selection import train_test_split
5+
from sklearn.metrics import mean_squared_error as MSE
6+
import matplotlib.pyplot as plt
7+
dataset = pd.read_csv("LinearData.csv")
8+
X, y = dataset.iloc[:, :-1], dataset.iloc[:, -1]
9+
train_X, test_X, train_y, test_y = train_test_split(X, y,test_size = 0.25, random_state = 123)
10+
xgb_r = xg.XGBRegressor(objective ='reg:linear', n_estimators = 15, seed = 123)
11+
xgb_r.fit(train_X, train_y)
12+
pred = xgb_r.predict(test_X)
13+
print("RMSE : % f" ,np.sqrt(MSE(test_y, pred)))

Diff for: LinearData.csv

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
X,Y
2+
1,953
3+
2,2068
4+
3,2871
5+
4,3972
6+
5,5240
7+
6,5610
8+
7,7196
9+
8,7936
10+
9,8577
11+
10,10950
12+
11,11077
13+
12,12468
14+
13,13780
15+
14,13888
16+
15,14325
17+
16,14496
18+
17,16116
19+
18,17064
20+
19,20387
21+
20,18620
22+
21,20517
23+
22,22264
24+
23,22770
25+
24,25344
26+
25,23450
27+
26,28522
28+
27,25920
29+
28,30072
30+
29,31813
31+
30,32370

0 commit comments

Comments
 (0)