コード例 #1
0
    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)
コード例 #2
0
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")
コード例 #3
0
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']