-
Notifications
You must be signed in to change notification settings - Fork 1
/
MachineLearningReduced.py
64 lines (63 loc) · 2.53 KB
/
MachineLearningReduced.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
64
import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm
import pandas as pd
from numpy import array
header1 = ["f11","f12","f13","f14","f15","f16","f18","f23","f24","f25","f26","f27","f28"]
header2 = ["MangaName"]
data_df2 = pd.DataFrame.from_csv("D:/semesters/graduation project - manga/mangaNames.csv")
oldY = np.array(data_df2[header2].values)
y=[]
for name in oldY:
y.append(name[0])
FeaturesFile = open('D:/semesters/graduation project - manga/predictedReduced.csv', 'w+')
FeaturesFile.write("Manga,Prediction 1,Prediction 2,Prediction 3\n")
for mangaNameToPredictName in y :
PredictFileString = mangaNameToPredictName
mangaNameToPredict = mangaNameToPredictName
predictFeatures = [];
deleteManga = [];
def Build_Data_Set(features = header1, features1 = header2, toDelete = deleteManga):
data_df = pd.DataFrame.from_csv("D:/semesters/graduation project - manga/features.csv")
X = np.array(data_df[features].values)
data_df2 = pd.DataFrame.from_csv("D:/semesters/graduation project - manga/mangaNames.csv")
oldY = np.array(data_df2[features1].values)
y=[]
for name in oldY:
y.append(name[0])
for mangaName in deleteManga :
try :
mangaIndex = y.index(mangaName);
except:
mangaIndex = y.tolist().index(mangaName);
if len(toDelete)==1 :
predictFeatures.append(X[mangaIndex])
y = np.delete(y, mangaIndex, 0)
X = np.delete(X, mangaIndex, 0)
return X,y
def Analysis():
X,y = Build_Data_Set()
X = array( X )
y = array( y )
C = 100 # SVM regularization parameter
#clf1 = (svm.SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
#decision_function_shape='ovr', degree=3, gamma='auto', kernel='rbf',
#max_iter=-1, probability=False, random_state=None, shrinking=True,
#tol=0.001, verbose=False))
#clf1 = (svm.SVC(kernel='poly', degree=2, C=C))
clf1 = (svm.SVC(kernel='linear', C=C))
clf1 = clf1.fit(X, y)
value1 = clf1.predict(predictFeatures);
print(value1[0])
return value1[0]
deleteManga.append(mangaNameToPredict)
x = Analysis()
PredictFileString += ","+x
deleteManga.append(x)
x = Analysis()
PredictFileString += ","+x
deleteManga.append(x)
x = Analysis()
PredictFileString += ","+x
PredictFileString += "\n"
FeaturesFile.write(PredictFileString)