def gen_profile(vect=None): ''' Input lifestyle vector return person obj with income, expenditure, purchase amount by category. ''' sav_rating = determine_saving_rating() gender = random.choice(['male', 'female']) username = gen.generate_name().lower() if not vect: if gender == 'male': vect = gc.generate_test_cases(1)[0] else: vect = gc.generate_test_cases(1)[1] trans_hist = create_transaction_history(vect) income, saving = determine_inv_sav(trans_hist, sav_rating) email = gen.generate_email(username) age = str(random.choice(list(range(16, 81)))) rent = determine_rent() category = str(predict(vect)) utilities = determine_utility(rent) Location = random.choice( ['Toronto', 'Calgary', 'Vancover', 'Montreal', 'Edmonton']) password = "******" return Person(category, username, gender, password, email, age, income, saving, rent, utilities, trans_hist)
def train(n): training_data = gc.generate_test_cases(n) training_data = np.asarray(training_data) clusterer = mixture.GaussianMixture(n_components=15) clusterer.fit(training_data) joblib.dump(clusterer, "Classification/training_data.pkl") predict()
def predict(toPredict=None): """ Predicting a vector of dimensions 12 to output a value from 0 to 15. @param toPredict: vector of dimensions 12 """ if not toPredict: toPredict = gc.generate_test_cases(1)[0] toPredict = np.asarray(toPredict) toPredict = toPredict.reshape(1, -1) clusterer = joblib.load("Classification/training_data.pkl") class_ = clusterer.predict(toPredict) return class_[0]