Skip to content

Instantly share code, notes, and snippets.

RegressionDataset data(inputs, labels);
LinearRegression trainer;// trainer for linear regression model
LinearModel<> model; // linear model
importCSV(inputs, "input.csv"); // storing the values in specific container by specifying the path of csv
importCSV(labels, "label.csv");
Data<RealVector> inputs; //container for storing the x values
Data<RealVector> labels; //conatiner for storing the y values
#include <bits/stdc++.h> //header file for all basic c++ libraries
#include <shark/Data/Csv.h> //header file ro importing data in csv format
#include <shark/ObjectiveFunctions/Loss/SquaredLoss.h> //header file for implementing squared loss function
#include <shark/Algorithms/Trainers/LinearRegression.h>// header file for implementing linear regression
best_clf_random.fit(X_train, Y_train)
# Make predictions using the new model.
best_train_predictions = best_clf_random.predict(X_train)
best_test_predictions = best_clf_random.predict(X_test)
# Calculate the f1_score of the new model.
print('The training F1 Score is', f1_score(best_train_predictions, Y_train))
print('The testing F1 Score is', f1_score(best_test_predictions, Y_test))
scores = cross_val_score(best_clf_random, X_train, Y_train, cv=5, scoring='f1_macro')
scores.mean()
best_clf_random = generate_clf_from_search("Random",
clf,
parameters,
scorer,
X_train,
Y_train)
best_clf_grid.fit(X_train, Y_train)
# Make predictions using the new model.
best_train_predictions = best_clf_grid.predict(X_train)
best_test_predictions = best_clf_grid.predict(X_test)
# Calculate the f1_score of the new model.
print('The training F1 Score is', f1_score(best_train_predictions, Y_train))
print('The testing F1 Score is', f1_score(best_test_predictions, Y_test))
scores = cross_val_score(best_clf_grid, X_train, Y_train, cv=5, scoring='f1_macro')
scores.mean()
best_clf_grid = generate_clf_from_search("Grid",
clf,
parameters,
scorer,
X_train,
Y_train)