@Ansistrawberry/

CheeryNeatProduct

Python

No description

fork
loading
Files
  • main.py
  • insurance.csv
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pandas as pd
#load data
df = pd.read_csv('insurance.csv')
#Split data to X,y
X = df.iloc[:, :-1].values
y = df.iloc[:, -1].values
# Encoder data
from sklearn.preprocessing import OneHotEncoder, LabelEncoder
labelencoder_X = LabelEncoder()
X[:, 1] = labelencoder_X.fit_transform(X[:, 1])
X[:, 4] = labelencoder_X.fit_transform(X[:, 4])
X[:, 5] = labelencoder_X.fit_transform(X[:, 5])
onehotencoder = OneHotEncoder(categorical_features = [1])
onehotencoder = OneHotEncoder(categorical_features = [4])
onehotencoder = OneHotEncoder(categorical_features = [5])
X = onehotencoder.fit_transform(X).toarray()
# Split data tp train, test
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state = 0)
# fitting data to Linear Regression
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train, y_train)
y_pred = model.predict([[0, 0, 1, 0, 18, 1, 24.1, 0, 0]])
y_score = model.score(X_test, model.predict(X_test))
# print y_predict and the accuracy
print('Prediction: {}'.format(y_pred))
print('The Accuracy: {}'.format(y_score))