MoRebaie
MoRebaie

Reputation: 23

calculating recall & precision using RBF SVC model m

1- Using the already defined RBF SVC model m, run a grid search on the parameters C and gamma, for values [0.01, 0.1, 1, 10]. The grid search should find the model that best optimizes for recall. How much better is the recall of this model than the precision? (Compute recall - precision to 3 decimal places)

(Use y_test and X_test to compute precision and recall.)

2- Using the already defined RBF SVC model m, run a grid search on the parameters C and gamma, for values [0.01, 0.1, 1, 10]. The grid search should find the model that best optimizes for precision. How much better is the precision of this model than the recall? (Compute precision - recall to 3 decimal places)

(Use y_test and X_test to compute precision and recall.)

Upvotes: 1

Views: 3215

Answers (1)

Ahmed Karam Hassan
Ahmed Karam Hassan

Reputation: 59

Assuming that Model 'm' is defined, here's how to make Grid search:

1- Initialize the Grid parameters c & Gamma.

2- Run the Grid search using the (model (m),initialized parameters, and set the scoring to 'recall') -for the second question you will set it to 'precision'.

3- fit the model using training data (X_train & y_train).

4- calculate "y_scores" by using function predict on "X_test".

5- calculate the scores of precision and recall.

Here's the code using scikit learn for the problem:

from sklearn.metrics import recall_score, precision_score
from sklearn.model_selection import GridSearchCV

grid_params = {'gamma': [0.01, 0.1, 1, 10],'C': [0.01, 0.1, 1, 10]}
grid_recall = GridSearchCV(m, param_grid = grid_params , scoring = 'recall')
grid_recall.fit(X_train, y_train)
y_scores = grid_recall.predict(X_test)

print('Difference: ', recall_score(y_test, y_scores) -  precision_score(y_test, y_scores))

Upvotes: 4

Related Questions