Esempio n. 1
0
 def test1(self):
     df = get_iris()
     out_df = sort(df,
                   input_cols=['species', 'petal_length'],
                   is_asc=['desc', 'asc'])['out_table']
     print(df)
     print(out_df)
Esempio n. 2
0
 def test_validation(self):
     df = get_iris()
     with self.assertRaises(BrighticsFunctionException) as bfe:
         out_df = sort(df, input_cols=[], is_asc=['desc'])['out_table']
         
     test_errors = bfe.exception.errors
     self.assertTrue({'0033': ['input_cols']} in test_errors)
Esempio n. 3
0
 def test_groupby1(self):
     df = get_iris()
     train_out = xgb_regression_train(
         df,
         feature_cols=['sepal_length', 'sepal_width', 'petal_length'],
         label_col='petal_width',
         group_by=['species'])
     predict_out = xgb_regression_predict(df, train_out['model'])
     print(predict_out['out_table'][['petal_width', 'prediction']])
Esempio n. 4
0
 def test3(self):
     # df = df_iris.copy().query(''' species != 'setosa' ''')
     df = get_iris()
     print(df)
     out = add_expression_column_if(
         df, 'encoded_species',
         ['''species == 'setosa' ''', '''species == 'virginica' '''],
         ['1.0', '2.0'], '0.0')['out_table']
     print(out['encoded_species'][48:102])
Esempio n. 5
0
def get_iris_randomgroup():
    df = get_iris()
    random_group1 = []
    random_group2 = []
    random_group2_map = {1: 'A', 2: 'B'}
    for i in range(len(df)):
        random_group1.append(random.randint(1, 2))
        random_group2.append(random_group2_map[random.randint(1, 2)])
    df['random_group1'] = random_group1
    df['random_group2'] = random_group2
    return df
Esempio n. 6
0
    def groupby1(self):
        df = get_iris()
        random_group = []
        for i in range(len(df)):
            random_group.append(random.randint(1, 2))
        df['random_group'] = random_group

        train_out = svm_classification_train(df,
                                             feature_cols=[
                                                 'sepal_length', 'sepal_width',
                                                 'petal_length', 'petal_width'
                                             ],
                                             label_col='species',
                                             group_by=['random_group'])
        predict_out = svm_classification_predict(df, train_out['model'])
        print(predict_out['out_table'][['species', 'prediction']])
Esempio n. 7
0
    def test1(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'])
        print(predict_out['out_table'][['species', 'prediction']])
Esempio n. 8
0
    def test_predict_thresholds(self):
        iris = get_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'],
                                                 thresholds=[0.1, 0.2, 0.3])
        print(predict_out['out_table'][['species', 'prediction']])
Esempio n. 9
0
 def setUp(self):
     print("*** Chi-square Test of Independence UnitTest Start ***")
     self.iris = get_iris()
Esempio n. 10
0
 def setUp(self):
     print("*** SQL UnitTest Start ***")
     df_iris = get_iris()
Esempio n. 11
0
    
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""

import unittest
import pandas as pd
import numpy as np
from brightics.function.test_data import get_iris
from brightics.function.transform import sql_execute
from brightics.common.repr import strip_margin

df_iris = get_iris()


class SQLTest(unittest.TestCase):
    def test_percentile(self):
        query = strip_margin('''
        | SELECT percentile(sepal_length, 25) FROM #{DF(0)}
        |''')

        result_df = sql_execute(df_iris, query)['out_table']
        print(result_df)
        self.assertEqual(5.1, result_df.values[0][0],
                         'The percentile is not correct.')

    def test_array(self):
        query = strip_margin('''
Esempio n. 12
0
 def kmeans_groupby1(self):
     df = get_iris()
     train_out = kmeans_train_predict(df, input_cols=['sepal_length', 'sepal_width', 'petal_length', 'petal_width'], group_by=['species'])
     predict_out = kmeans_predict(df, train_out['model'])
     print(predict_out['out_table'])
Esempio n. 13
0
 def test2(self):
     df = get_iris()
     out_df = sort(df, input_cols=[], is_asc=['desc'])['out_table']
     print(df)
     print(out_df)