Esempio n. 1
0
    def test_ratio(self):
        df_iris = load_iris()
        res = split_data(table=df_iris,
                         train_ratio=1.0,
                         test_ratio=1.0,
                         random_state=12345,
                         shuffle=True,
                         stratify=None)
        df_train = res['train_table']
        df_test = res['test_table']

        self.assertEqual(75, len(df_train), 'wrong size of train table')
        self.assertEqual(75, len(df_test), 'wrong size of test table')

        self.assertListEqual([5.0, 3.4, 1.6, 0.4, 'setosa'],
                             df_train.loc[0].tolist(),
                             'incorrect train data in the 1st row')
        self.assertListEqual([7.1, 3.0, 5.9, 2.1, 'virginica'],
                             df_train.loc[1].tolist(),
                             'incorrect train data in the 2nd row')
        self.assertListEqual([6.7, 3.1, 4.7, 1.5, 'versicolor'],
                             df_train.loc[2].tolist(),
                             'incorrect train data in the 3rd row')

        self.assertListEqual([5.6, 2.5, 3.9, 1.1, 'versicolor'],
                             df_test.loc[0].tolist(),
                             'incorrect train data in the 1st row')
        self.assertListEqual([4.4, 3.2, 1.3, 0.2, 'setosa'],
                             df_test.loc[1].tolist(),
                             'incorrect train data in the 2nd row')
        self.assertListEqual([6.3, 3.3, 4.7, 1.6, 'versicolor'],
                             df_test.loc[2].tolist(),
                             'incorrect train data in the 3rd row')
Esempio n. 2
0
 def test_predict_thresholds(self):
     iris = load_iris()
     
     df_splitted = split_data(table=iris, train_ratio=0.7, test_ratio=0.3)
     train_df = df_splitted['train_table']
     test_df = df_splitted['test_table']
     
     train_out = svm_classification_train(table=train_df, feature_cols=['sepal_length', 'sepal_width', 'petal_length', 'petal_width'], label_col='species')
     
     predict_out = svm_classification_predict(table=test_df, model=train_out['model'], thresholds=[0.1, 0.2, 0.3])
Esempio n. 3
0
 def test1(self):
     iris = load_iris()
     
     df_splitted = split_data(table=iris, train_ratio=0.7, test_ratio=0.3)
     train_df = df_splitted['train_table']
     test_df = df_splitted['test_table']
     
     train_out = svm_classification_train(table=train_df, feature_cols=['sepal_length', 'sepal_width', 'petal_length', 'petal_width'], label_col='species')
     # print(train_out['model']['svc_model'])
     
     predict_out = svm_classification_predict(table=test_df, model=train_out['model'])
     print(predict_out['out_table'][['species', 'prediction']])
Esempio n. 4
0
    def predict_thresholds(self):
        iris = get_iris()

        df_splitted = split_data(iris, 0.7, 0.3)
        train_df = df_splitted['train_table']
        test_df = df_splitted['test_table']

        train_out = svm_classification_train(train_df,
                                             feature_cols=[
                                                 'sepal_length', 'sepal_width',
                                                 'petal_length', 'petal_width'
                                             ],
                                             label_col='species')
        # print(train_out['model']['svc_model'])

        predict_out = svm_classification_predict(test_df,
                                                 train_out['model'],
                                                 thresholds=[0.1, 0.2, 0.3])
        print(predict_out['out_table'][['species', 'prediction']])