def test_knn_predict(self): """ Testing the predicted values of the knnRegressor """ y_predict = [2, 2, 3, 3] my_knn = knnRegressor("y~.", data=df1) my_knn.fit() self.assertEqual(y_predict, my_knn.predict(df1).tolist())
def test_knn_predict_with_k_value(self): """ Testing the predicted values of the knnRegressor with 2 nearest neighbors """ y_expected = [1, 1, 4.5, 4.5] my_knn = knnRegressor("y~.", k=2, data=df1) my_knn.fit() y_predicted = my_knn.predict(df1) self.assertEqual(y_expected, y_predicted.tolist())
def test_knn_predict(self): """ Testing the predicted values of the knnClassifier """ y_predict = [ 0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.3333333333333333 ] my_knn = knnRegressor("y~.", data=df_cl) my_knn.fit() self.assertEqual(y_predict, my_knn.predict(df1).tolist())
def test_knn_fit(self): """ Testing the fit method of the knnClassifier and making sure it is not raising error """ my_knn = knnRegressor("y~.", data=df_cl) my_knn.fit()
def test_knn_init(self): """ Making sure if you are able to create instance of the knnRegressor. """ my_model = knnRegressor("y~.", df1)
from src.models.BaseModel import BaseModel if __name__ == "__main__": model_formula = FormulaParser('dist~speed', ["speed", "dist"]) df = pd.DataFrame({"x": [0, 0, 1, 1], "y": [0, 2, 4, 5]}) print('Data to fit the model: \n', df) my_lm = lm("y~.", data=df) my_lm.fit() my_lm.summary() # df1 = pd.DataFrame({"x": [0, 0, 1, 1], "y": [0, 2, 4, 5]}) predict_df = pd.DataFrame({"x": [0, 1]}) my_lm = lm("y~.", data=df1) my_lm.fit() my_lm.summary() y_hat = my_lm.predict(predict_df) print(y_hat) my_knn = knnRegressor("y~.", data=df1) my_knn.fit() print(my_knn.predict(df1)) df2 = pd.DataFrame({"x": [0, 1, 2, 3], "y": [0, 0, 1, 1]}) my_knn_class = knnClassifier("y~.", data=df2) my_knn_class.fit() print(my_knn_class.predict_proba(df2))