Sep-15-2021, 12:53 PM
I am doing SVM and I always get the accuracy of 0.84 even after tuning my hyperparameters. Even if I play with scaling of the data, it does not seem to make the difference.
Any suggestions? Thanks!
Any suggestions? Thanks!
# Encoding categorical data in y labelencoder_y = LabelEncoder() y = labelencoder_y.fit_transform(y) #self.X_train, self.X_test, self.y_train, self.y_test = train_test_split(X, y, test_size=0.2, random_state = 40) self.X_train = X self.X_test = X self.y_train = y self.y_test = y #scaling features sc = StandardScaler() self.X_train = sc.fit_transform(self.X_train) self.X_test = sc.transform(self.X_test) # Fit to the training data self.grid.fit(self.X_train, self.y_train) y_pred = self.grid.predict(self.X_test)And my model is in constructor. Note, I did try out other classifiers, and it seemed not to make the difference in my prediction. I do get smaller accuracy but nothing larger than 0.84. With tree for example, I get down to 0.74:)
def __init__(self, datafile = 'data/Customer_telecom.csv'): self.df = pd.read_csv(datafile) self.linear_reg = LogisticRegression(random_state=1234) # Instantiate the classifier self.clf = RandomForestClassifier() # defining parameter range self.grid = GridSearchCV(svm.SVC(), param_grid={'C': [0.1, 1, 10, 100, 1000], 'gamma': [1, 0.1, 0.01, 0.001, 0.0001], 'kernel': ['rbf', 'poly','sigmoid']}, refit = True, verbose = 3) self.clf_svm = svm.SVC() self.clf_kn = KNeighborsClassifier(n_neighbors=5) self.clf_tree = tree.DecisionTreeClassifier() self.reg_grid = GridSearchCV(estimator=LogisticRegression(random_state=1234), param_grid={'max_iter': [20, 50, 100, 200, 500, 1000], 'solver': ['newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga'], 'class_weight': ['balanced'] }, verbose=1, cv=10, n_jobs=-1)