Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run_full_test(USE_CUDA, CACHE_ENCODED_DATA, SELFAWARE, PLINEAR):
'''
Run full test example with home_rentals dataset
'''
lightwood.config.config.CONFIG.USE_CUDA = USE_CUDA
lightwood.config.config.CONFIG.PLINEAR = PLINEAR
config = {'input_features': [
{'name': 'number_of_bathrooms', 'type': 'numeric'}, {'name': 'sqft', 'type': 'numeric'},
{'name': 'days_on_market', 'type': 'numeric'},
{'name': 'neighborhood', 'type': 'categorical','dropout':0.4}],
'output_features': [{'name': 'number_of_rooms', 'type': 'categorical',
'weights':{
'0': 0.8,
'1': 0.6,
'2': 0.5,
'3': 0.7,
'4': 1,
}
},{'name': 'rental_price', 'type': 'numeric'},{'name': 'location', 'type': 'categorical'}],
'data_source': {'cache_transformed_data':CACHE_ENCODED_DATA},
'mixer':{'class': lightwood.BUILTIN_MIXERS.NnMixer, 'selfaware': SELFAWARE}}
import lightwood
import random
import pandas as pd
import numpy as np
lightwood.config.config.CONFIG.HELPER_MIXERS = False
random.seed(66)
n = 500
m = 800
train = True
data_train = {}
data_test = {}
for data, nr_ele in [(data_train,n), (data_test,m)]:
for i in range(1,5):
data[f'x_{i}'] = [random.random()*50 + 25 for _ in range(nr_ele)]
data['y'] = [data['x_1'][i] * 0.9 + data['x_2'][i] * 0.09 + data['x_3'][i] * 0.009 + data['x_4'][i] * 0.0009 for i in range(nr_ele)]
data_train = pd.DataFrame(data_train)
import pandas
import random
import lightwood
from lightwood import Predictor
import os
from sklearn.metrics import r2_score
import numpy as np
lightwood.config.config.CONFIG.HELPER_MIXERS = False
random.seed(66)
### Generate a dataset
n = 100
m = n * 100
op = '*'
# generate random numbers between -10 and 10
data_train = {'x': [random.randint(-15, 5) for i in range(n)],
'y': [random.randint(-15, 5) for i in range(n)]}
data_test = {'x': [random.randint(-15, 5) for i in range(m)],
'y': [random.randint(-15, 5) for i in range(m)]}
if op == '/':
for i in range(n):
def predict(self, mode='predict', ignore_columns=[]):
lightwood.config.config.CONFIG.USE_CUDA = self.transaction.lmd['use_gpu']
lightwood.config.config.CONFIG.CACHE_ENCODED_DATA = not self.transaction.lmd['force_disable_cache']
lightwood.config.config.CONFIG.SELFAWARE = self.transaction.lmd['use_selfaware_model']
if mode == 'predict':
# Doing it here since currently data cleanup is included in this, in the future separate data cleanup
lightwood_config = self._create_lightwood_config()
df = self.transaction.input_data.data_frame
if mode == 'validate':
df = self.transaction.input_data.validation_df
elif mode == 'test':
df = self.transaction.input_data.test_df
if self.transaction.lmd['model_order_by'] is not None and len(self.transaction.lmd['model_order_by']) > 0:
df = self._create_timeseries_df(df)
if self.predictor is None:
def predict(self, mode='predict', ignore_columns=[]):
lightwood.config.config.CONFIG.USE_CUDA = self.transaction.lmd['use_gpu']
lightwood.config.config.CONFIG.CACHE_ENCODED_DATA = not self.transaction.lmd['force_disable_cache']
lightwood.config.config.CONFIG.SELFAWARE = self.transaction.lmd['use_selfaware_model']
if mode == 'predict':
# Doing it here since currently data cleanup is included in this, in the future separate data cleanup
lightwood_config = self._create_lightwood_config()
df = self.transaction.input_data.data_frame
if mode == 'validate':
df = self.transaction.input_data.validation_df
elif mode == 'test':
df = self.transaction.input_data.test_df
if self.transaction.lmd['model_order_by'] is not None and len(self.transaction.lmd['model_order_by']) > 0:
df = self._create_timeseries_df(df)
if self.predictor is None:
self.predictor = lightwood.Predictor(load_from_path=self.transaction.lmd['lightwood_data']['save_path'])