Skip to main content
added 1633 characters in body
Source Link
J.D.
  • 921
  • 5
  • 20
  • 31

[EDIT 3] I don't kow if I am doing it correctly but to see if the dataset is balanced or not, I looked how many times in a dataset I have optimization high (H) and optimizaion low (L), which is also what I would like to predict for new samples.

Sorry if I am not really precise but I just started with machine learning.

What I did is the following:

Y = list(data['opt'])

MlistY = Y

MlistY.count('L')

which returns : 17924

MlistY.count('H')

which returns: 12076

Moreover I have also tried to use TfidfVectorizer and what I did is:

from sklearn.feature_extraction.text import TfidfVectorizer
vectorizer = TfidfVectorizer(smooth_idf=False, sublinear_tf=False,norm=None, 
analyzer='word') 

x = vectorizer.fit_transform(opcodes)

a = vectorizer.vocabulary_

X = list(a.values())

X_all = np.array(X).reshape(-1,1)

Y = list(data['opt'])[:395]

MlistY = Y

y_all = np.array(MlistY)

X_train, X_test, y_train, y_test = train_test_split(X_all, y_all, 
test_size=0.3, random_state=15)

from sklearn.svm import SVC
model = SVC(kernel = 'linear',C= 1)

model.fit(X_train,y_train)

y_pred = model.predict(X_test)
print(confusion_matrix(y_test, y_pred))
print(classification_report(y_test, y_pred))

model.score(X_test,y_test) 

and in this case the accuracy is : 0.5294117647058824

Moreover, if I print the classification report I find this:

enter image description here

in particular this is for the case of TfidfVectorizer.

[EDIT 3] I don't kow if I am doing it correctly but to see if the dataset is balanced or not, I looked how many times in a dataset I have optimization high (H) and optimizaion low (L), which is also what I would like to predict for new samples.

Sorry if I am not really precise but I just started with machine learning.

What I did is the following:

Y = list(data['opt'])

MlistY = Y

MlistY.count('L')

which returns : 17924

MlistY.count('H')

which returns: 12076

Moreover I have also tried to use TfidfVectorizer and what I did is:

from sklearn.feature_extraction.text import TfidfVectorizer
vectorizer = TfidfVectorizer(smooth_idf=False, sublinear_tf=False,norm=None, 
analyzer='word') 

x = vectorizer.fit_transform(opcodes)

a = vectorizer.vocabulary_

X = list(a.values())

X_all = np.array(X).reshape(-1,1)

Y = list(data['opt'])[:395]

MlistY = Y

y_all = np.array(MlistY)

X_train, X_test, y_train, y_test = train_test_split(X_all, y_all, 
test_size=0.3, random_state=15)

from sklearn.svm import SVC
model = SVC(kernel = 'linear',C= 1)

model.fit(X_train,y_train)

y_pred = model.predict(X_test)
print(confusion_matrix(y_test, y_pred))
print(classification_report(y_test, y_pred))

model.score(X_test,y_test) 

and in this case the accuracy is : 0.5294117647058824

Moreover, if I print the classification report I find this:

enter image description here

in particular this is for the case of TfidfVectorizer.

added 904 characters in body
Source Link
J.D.
  • 921
  • 5
  • 20
  • 31

[EDIT 2] What also I have tried to do is the following:

opcodes_ordered = pd.factorize(opcodes)

opcodes_ordered_true = opcodes_ordered[0]

opcodes_ordered_true

which gives as output : array([ 0, 0, 0, ..., 22, 3, 5], dtype=int64)

X_all_2 = opcodes_ordered_true.reshape(-1,1)[:1000]

y_all_2 = list(data['opt'])[:1000]

X_train_2, X_test_2, y_train_2, y_test_2 = train_test_split(X_all_2, 
y_all_2, test_size=0.2, random_state=15)

model_2 = SVC(kernel = 'linear',gamma = 1.0)

model_2.fit(X_train_2,y_train_2)

y_pred_2 = model_2.predict(X_test_2)
print(confusion_matrix(y_test_2, y_pred_2))
print(classification_report(y_test_2, y_pred_2))

model_2.score(X_test_2,y_test_2) 

but I get as accuracy : 0.56

which is still low. Does anybdy know how could I have better accuracy? Thank's in advance.

[EDIT 2] What also I have tried to do is the following:

opcodes_ordered = pd.factorize(opcodes)

opcodes_ordered_true = opcodes_ordered[0]

opcodes_ordered_true

which gives as output : array([ 0, 0, 0, ..., 22, 3, 5], dtype=int64)

X_all_2 = opcodes_ordered_true.reshape(-1,1)[:1000]

y_all_2 = list(data['opt'])[:1000]

X_train_2, X_test_2, y_train_2, y_test_2 = train_test_split(X_all_2, 
y_all_2, test_size=0.2, random_state=15)

model_2 = SVC(kernel = 'linear',gamma = 1.0)

model_2.fit(X_train_2,y_train_2)

y_pred_2 = model_2.predict(X_test_2)
print(confusion_matrix(y_test_2, y_pred_2))
print(classification_report(y_test_2, y_pred_2))

model_2.score(X_test_2,y_test_2) 

but I get as accuracy : 0.56

which is still low. Does anybdy know how could I have better accuracy? Thank's in advance.

added 105 characters in body
Source Link
J.D.
  • 921
  • 5
  • 20
  • 31

[EDIT] I also tried to reduce the number of features, but by doing so I only got a small improvement.

[EDIT] I also tried to reduce the number of features, but by doing so I only got a small improvement.

added 1130 characters in body
Source Link
J.D.
  • 921
  • 5
  • 20
  • 31
Loading
added 105 characters in body
Source Link
J.D.
  • 921
  • 5
  • 20
  • 31
Loading
added 184 characters in body
Source Link
J.D.
  • 921
  • 5
  • 20
  • 31
Loading
Source Link
J.D.
  • 921
  • 5
  • 20
  • 31
Loading