def get(self, request, *arg, **kwargs): gp = GenderPredictor() gp.train_and_test() context = { "form": NameForm, } return render(request, 'gender_app/home.html',context)
def search(): gp = GenderPredictor() accuracy = gp.train_and_test(training_percent=0.80) * 100 features = gp.get_most_informative_features(n=10) name = request.form['query'].lower() finalgender = gp.classify_name(name) gender_dict = find_gender(name) if finalgender[0] == 'Male': return render_template("male.html") else: return render_template("female.html")
def post(self, request, **kwargs): if 'submit' in request.POST: name=request.POST['name'] gp = GenderPredictor() gp.train_and_test() detected_gender = gp.classify(name) context = { "name" : name, "gender": detected_gender } return render(request, 'gender_app/predict_gender.html',context)
from gender_predictor import GenderNames, GenderPredictor, get_predictor_from_file, get_predictor_from_pickle if __name__ == '__main__': # Example 1 how use it print("Example 1 Sami:") gn = GenderNames() gn = gn.load_from_files(path_female='data/female.txt', path_male='data/male.txt') gp = GenderPredictor(gn, female_label='Female', male_label='Male') print(gp.get_gender('Sami')) print() print("Example 2 Pekka:") gn = GenderNames() gn = gn.load_from_files(path_female='data/female.txt', path_male='data/male.txt') gp = GenderPredictor(gn, female_label='Female', male_label='Male') print(gp.get_gender('Pekka')) print()
col3.append(10) col3.append(10) col3.append(12) col3.append(10) col3.append(11) col3.append(12) col3.append(10) col3.append(10) col3.append(9) col3.append(9) col3.append(9) print(len(col3)) data_dict['Grade'] = col3 print(len(data_dict['Grade'])) # Getting the gender gen = GenderPredictor() gen.train_and_test() col4 = [gen.classify(i.split(" ")[0]) for i in col1] print(col4) data_dict['Gender'] = col4 df = pd.DataFrame.from_dict(data_dict) df.head() df.replace('M', 'male', inplace=True) df.replace('F', 'female', inplace=True) df.to_csv("data/m132-student-data.csv")
import pandas as pd from os import getcwd, listdir from gender_predictor import GenderPredictor # Get the Student Data data_path = getcwd() + "/data" listdir(data_path) df = pd.read_csv(f"{data_path}/{listdir(data_path)[0]}") # Instantiate the Class gp = GenderPredictor() # Train the Model gp.train_and_test() # Get List of Students' First Names student_names = [name.split(" ")[0] for name in df['Student Name'].tolist()] # Get Predictions gender_preds = [gp.classify(name) for name in student_names] # Add Gender Column to the Data Frame df['Gender'] = gender_preds # Save New Data df.to_csv(f"{data_path}/{listdir(data_path)[0]}", index=False) df['Gender']
'ethnicity', 'race' ] candidate = [] age_attribute = [] name = gender = age = country = race = ethnicity = False for i in zip(columns, predicted_labels): if i[0].lower() in sensitive or i[1].lower() in sensitive: candidate.append(i[0]) if i[0].lower() in [ 'name', 'first_name', 'first name' ] or i[1].lower() in ['name', 'first_name', 'first name']: name = i[0] if i[0].lower() in ['sex', 'gender' ] or i[1].lower() in ['sex', 'gender']: gender = i[0] if i[0].lower() in ['age'] or i[1].lower() in ['age']: age = i[0] age_attribute.append(i[0]) if i[0].lower() in ['country'] or i[1].lower() in ['country']: country = i[0] if i[0].lower() in ['race'] or i[1].lower() in ['race']: race = i[0] if i[0].lower() in ['ethnicity'] or i[1].lower() in ['ethnicity']: ethnicity = i[0] return header, predicted_labels, candidate, name, gender, age, country, race, ethnicity, age_attribute if __name__ == "__main__": gp = GenderPredictor() gp.train_and_test()