-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpredictor.py
More file actions
33 lines (25 loc) · 1.01 KB
/
predictor.py
File metadata and controls
33 lines (25 loc) · 1.01 KB
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
30
31
32
import pandas as pd
# Importing the dataset
dataset = pd.read_csv('data/odi.csv')
X = dataset.iloc[:,[7,8,9,12,13,14]].values
y = dataset.iloc[:, 15].values
# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)
# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
# Training the dataset
from sklearn.linear_model import LogisticRegression
lin = LogisticRegression(random_state=0, solver='lbfgs',multi_class='multinomial')
lin.fit(X_train,y_train)
# Testing the dataset on trained model
y_pred = lin.predict(X_test)
score = lin.score(X_test,y_test)*100
print("R square value:" , score)
# Testing with a custom input
import numpy as np
new_prediction = lin.predict_proba(sc.transform(np.array([[100,2,10,23,52,350]])))
print("Prediction score:" , new_prediction[0][1]*100)