-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
75 lines (56 loc) · 1.89 KB
/
model.py
File metadata and controls
75 lines (56 loc) · 1.89 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
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
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
"""BlockchainProject.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1OlpfSxD34eNd3R-Ft9e9iV-9jnCF6Pmm
"""
import pandas as pd
import imblearn
print(imblearn.__version__)
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from imblearn.over_sampling import SMOTE
num_features = [
'hemoglobin',
'platelets',
'MPV',
'RBC',
'lymphocytes',
'MCHC',
'leukocytes',
'basophils',
'MCH',
'eosinophils',
'MCV',
'monocytes',
'RDW']
scaler = StandardScaler()
def algo(df, dp):
df = pd.DataFrame(df)
df[num_features] = scaler.fit_transform(df[num_features])
# oversample = RandomOverSampler(sampling_strategy=1)
smt = SMOTE(sampling_strategy=0.5, k_neighbors=5, random_state=1206)
y = df['covid19_Res']
X = df.drop(['covid19_Res'], axis=1)
X.head()
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=1206,
stratify=y)
X_over, y_over = smt.fit_resample(X_train, y_train)
hyperPara = {'C': [10], 'gamma': [0.1], 'kernel': ['rbf'], 'shrinking': [True]}
# svm1 = SVC(C=10, gamma=0.1, kernel='rbf')
svm1 = SVC(C=10, gamma=0.1, kernel='rbf', class_weight={1: 10})
svm1.fit(X_train, y_train)
y_pred = svm1.predict(X_test)
y_pred = svm1.predict(dp)
print(f'You are\n {dp}')
if (y_pred[0] == 0):
y_pred = "Negative"
elif (y_pred[0] == 1):
y_pred = "Positive"
print(f'Current records number is {df.shape[0]}')
print(f'The AI predicts you are {y_pred}!')
from sklearn.metrics import classification_report
y_pred_2 = svm1.predict(X_test)
# print(f'Result is {classification_report(y_test, y_pred_2)}')
return y_pred