-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodel.py
64 lines (40 loc) · 1.41 KB
/
model.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
"""PCOS.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/12UOeCutZf80lbWnycldqBHzxVfZtrMLE
# Random Forest Classification
## Importing the libraries
"""
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import pickle
"""## Importing the dataset"""
dataset = pd.read_csv('PCOS_data.csv')
X = dataset.iloc[:, 3:].values
y = dataset.iloc[:, 2].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)
print(X_train)
print(y_train)
print(X_test)
print(y_test)
"""## Feature Scaling"""
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
print(X_train)
print(X_test)
"""## Training the Random Forest Classification model on the Training set"""
from sklearn.svm import SVC
classifier = SVC(kernel = 'rbf', random_state = 0)
classifier.fit(X_train, y_train)
"""## Loading model to compare the results"""
pickle.dump(classifier, open('model.pkl','wb'))
model = pickle.load(open('model.pkl','rb'))
"""## Predicting the Test set results"""
y_pred = classifier.predict(X_test)
print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))