Пример #1
0
def root():
    # global model
    global ridge
    form = HouseForms(csrf_enabled=False)
    return render_template("index1.html",
                           title="House Price Prediction",
                           form=form)
Пример #2
0
def root():
    global model
    form = HouseForms(csrf_enabled=False)
    return render_template("index1.html",
                           title="House Price Prediction",
                           form=form,
                           prediction="Awaiting You")
Пример #3
0
def index():
    # global model
    global ridge
    form = HouseForms(csrf_enabled=False)
    # if (request.method == "POST") and (form.validate()):

    user_dictionary = {
        'zip': [str(int(form.zipcode.data))],
        'type': [str(form.buildingType.data)],
        'beds': [float(form.bedrooms.data)],
        'baths': [float(form.bathrooms.data)],
        'sqrft': [float(form.Squarefeet.data)],
        'lot': [float(form.lotsize.data)],
        '$/sqrft': [float(form.per_sqrft.data)]
    }

    user_df = pd.DataFrame(user_dictionary)
    user_df_fit = pd.get_dummies(user_df, columns=['zip', 'type'])

    n = train_flask()

    for i in n.columns:
        if i in user_df_fit.columns:
            pass
        else:
            user_df_fit[i] = 0

    print(user_df_fit)

    # user_df_fit=user_df_fit.set_index('beds')

    # prediction = np.expm1(model.predict(user_df_fit))
    prediction = int(np.expm1(ridge.predict(user_df_fit)))

    # prediction=ridge.predict(user_df_fit)

    # prediction=model.predict(user_df_fit)
    # p = round(prediction[0],2)

    print([str(int(form.zipcode.data))])
    print([str(form.buildingType.data)])
    print([float(form.bedrooms.data)])
    print([float(form.bathrooms.data)])
    print([float(form.Squarefeet.data)])
    print([float(form.lotsize.data)])
    print([float(form.per_sqrft.data)])
    print(n.head())

    print(prediction)
    # else:
    #     prediction = "N/A"
    #     print("what")

    return render_template("index1.html",
                           title="House Price Prediction",
                           form=form,
                           prediction='${:,.2f}'.format(prediction))
Пример #4
0
def root():

    # if city_entered=="Irvine" or city_entered=="irvine":
    #     global irvine_ridge
    # else city_entered=="Tustin" or city_entered="tustin":
    #     global tustin_ridge

    form = HouseForms(csrf_enabled=False)
    return render_template("index1.html",
                           title="House Price Prediction",
                           form=form)
def index():
    global model
    form = HouseForms(csrf_enabled=False)
    # if (request.method == "POST") and (form.validate()):
    test_case = pd.DataFrame.from_dict({
        "Overall Quality": [float(form.overallQuality.data)],
        "Squarefeet": [float(form.area.data)],
        "Bedrooms": [float(form.bedrooms.data)],
        "Full Baths": [float(form.bathrooms.data)],
        "Garage Cars": [float(form.garage.data)],
        "Year Built": [float(form.yearBuilt.data)],
    })
    dummylist = []
    dummylist = 15 * [0]
    dummy_df = pd.DataFrame([dummylist])
    test_case[[
        "BldgType_1Fam", 'BldgType_2fmCon', 'BldgType_Duplex',
        'BldgType_Twnhs', 'BldgType_TwnhsE', 'CentralAir_N', 'CentralAir_Y',
        'HouseStyle_1.5Fin', 'HouseStyle_1.5Unf', 'HouseStyle_1Story',
        'HouseStyle_2.5Fin', 'HouseStyle_2.5Unf', 'HouseStyle_2Story',
        'HouseStyle_SFoyer', 'HouseStyle_SLvl'
    ]] = dummy_df
    test_case.loc[0, form.buildingType.data] = 1
    test_case.loc[0, form.houseStyle.data] = 1
    test_case.loc[0, form.centralAir.data] = 1

    prediction = model.predict(test_case)
    p = round(prediction[0], 2)
    print(p)
    # else:
    #     prediction = "N/A"
    #     print("what")

    return render_template("index1.html",
                           title="House Price Prediction",
                           form=form,
                           prediction=p)
Пример #6
0
def index():

    # global irvine_ridge
    form = HouseForms(csrf_enabled=False)
    # city=[str(form.city.data)]
    city = str(form.city.data)
    year_entered = int(form.yearBuilt.data)

    print(city)
    print('hello')

    n = train_flask()

    minimums = min_built()

    city_min = 0
    bin_sample = 0

    if city == "Irvine" or city == "irvine":
        city_min = minimums[0]
        bin_sample = n[0]['train_built'].unique()
        # ['train_built']
    if city == "tustin" or city == 'Tustin':
        city_min = minimums[1]
        bin_sample = n[2]['train_built'].unique()
    if city == "Costa Mesa" or "Costa mesa" or "costa mesa":
        city_min = minimums[2]
        bin_sample = n[4]['train_built'].unique()
    # if city=="Lake Forest" or "Lake forest" or "lake forest":
    #     city_min=minimums[3]
    #     bin_sample=n[6]['train_built'].unique()

    print(minimums)
    print(city_min)
    print(bin_sample)

    binned_yr = round((year_entered - city_min) / 10, 0)

    #closest existing bin to binned_yr

    def my_min(sequence):
        low = sequence[0]  # need to start with some value
        for i in sequence:
            if i < low:
                low = i
        return low

    diff = []
    for i in bin_sample:
        x = abs(i - binned_yr)
        diff.append(x)

    min_difference = my_min(diff)
    bin_index = diff.index(min_difference)
    right_bin = bin_sample[bin_index]

    print(type(right_bin))

    user_dictionary = {
        'zip': [str(int(form.zipcode.data))],
        'train_built': [str(right_bin)],
        'type': [str(form.buildingType.data)],
        'beds': [float(form.bedrooms.data)],
        'baths': [float(form.bathrooms.data)],
        'sqrft': [float(form.Squarefeet.data)],
        'lot': [float(form.lotsize.data)]
    }
    # 'city':[city]}
    # [str(form.city.data)]}
    print(f'user dictionariy: {user_dictionary}')
    # 'train_built':[str(form.yearBuilt.data)]

    user_df = pd.DataFrame(user_dictionary)
    user_df_fit = pd.get_dummies(user_df,
                                 columns=['zip', 'type', 'train_built'])

    # n=train_flask()

    # prediction=0
    if city == "irvine" or city == "Irvine":
        for i in n[1].columns:
            if i in user_df_fit.columns:
                pass
            else:
                user_df_fit[i] = 0
        prediction = int(np.expm1(irvine_ridge.predict(user_df_fit)))

    if city == "tustin" or city == "Tustin":
        for i in n[3].columns:
            if i in user_df_fit.columns:
                pass
            else:
                user_df_fit[i] = 0
        prediction = int(np.expm1(tustin_ridge.predict(user_df_fit)))

    if city == "Costa mesa" or city == "Costa Mesa" or city == "costa mesa":
        for i in n[5].columns:
            if i in user_df_fit.columns:
                pass
            else:
                user_df_fit[i] = 0
        prediction = int(np.expm1(costamesa_ridge.predict(user_df_fit)))

    # if city=="Lake Forest" or city=="Lake forest" or city=="lake forest":
    #     for i in n[7].columns:
    #         if i in user_df_fit.columns:
    #             pass
    #         else:
    #             user_df_fit[i]=0
    #     prediction = int(np.expm1(lakeforest_ridge.predict(user_df_fit)))

    print(user_df_fit)
    print(user_df_fit.columns)
    print(n[1].columns)
    # print(prediction)

    # prediction = int(np.expm1(tustin_ridge.predict(user_df_fit)))

    # prediction = int(np.expm1(tustin_ridge.predict(user_df_fit)))

    # print([str(int(form.zipcode.data))])
    # print([str(binned_yr)])
    # print([str(form.buildingType.data)])
    # print([float(form.bedrooms.data)])
    # print([float(form.bathrooms.data)])
    # print([float(form.Squarefeet.data)])
    # print([float(form.lotsize.data)])
    # print(n)

    # print(prediction)

    return render_template("index1.html",
                           title="House Price Prediction",
                           form=form,
                           prediction='${:,.2f}'.format(prediction))
Пример #7
0
def index():
    global model
    form = HouseForms(csrf_enabled=False)

    overallquality = []
    garagecars = []
    area = []
    fullbaths = []
    yearbuilt = []
    bedrooms = []
    buildingtype = ""
    centralair = ""
    housestyle = ""

    overallquality.append(form.overallQuality.data)
    garagecars.append(form.garage.data)
    area.append(form.area.data)
    fullbaths.append(form.bathrooms.data)
    yearbuilt.append(form.yearBuilt.data)
    bedrooms.append(form.bedrooms.data)
    buildingtype = form.buildingType.data
    centralair = form.centralAir.data
    housestyle = form.houseStyle.data

    # print(model)
    # test_case = pd.DataFrame.from_dict({
    #     "Overall Quality": [form.overallQuality.data],
    #     "Squarefeet": [form.area.data],
    #     "Bedrooms":[form.bedrooms.data],
    #     "Full Baths":[form.bathrooms.data],
    #     "Garage Cars":[form.garage.data],
    #     "Year Built":[form.yearBuilt.data],
    # })
    # print(test_case)
    test_case = pd.DataFrame()

    test_case["Overall Quality"] = overallquality
    test_case["Squarefeet"] = area
    test_case["Bedrooms"] = bedrooms
    test_case["Full Baths"] = fullbaths
    test_case["Garage Cars"] = garagecars
    test_case["Year Built"] = yearbuilt

    dummylist = []
    dummylist = 15 * [0]
    dummy_df = pd.DataFrame([dummylist])
    test_case[[
        "BldgType_1Fam", 'BldgType_2fmCon', 'BldgType_Duplex',
        'BldgType_Twnhs', 'BldgType_TwnhsE', 'CentralAir_N', 'CentralAir_Y',
        'HouseStyle_1.5Fin', 'HouseStyle_1.5Unf', 'HouseStyle_1Story',
        'HouseStyle_2.5Fin', 'HouseStyle_2.5Unf', 'HouseStyle_2Story',
        'HouseStyle_SFoyer', 'HouseStyle_SLvl'
    ]] = dummy_df
    test_case.loc[0, buildingtype] = 1
    test_case.loc[0, centralair] = 1
    test_case.loc[0, housestyle] = 1
    print(test_case)

    prediction = model.predict(test_case)
    print(prediction)
    prediction = round(prediction[0], 2)
    prediction = "${:,.2f}".format(prediction)
    print(prediction)

    return render_template("index1.html",
                           title="House Price Prediction",
                           form=form,
                           prediction=prediction)