<jupyter_start><jupyter_text>Data analysis<jupyter_code># Price
df["price"].describe()
# neighbourhood groups
df['neighbourhood_group'].value_counts()
# Avg Price in neighbourhood groups
avg_price = df.groupby("neighbourhood_group")["price"].mean()

print(avg_price)<jupyter_output>neighbourhood_group
Bronx             87.496792
Brooklyn         124.383207
Manhattan        196.875814
Queens            99.517649
Staten Island    114.812332
Name: price, dtype: float64<jupyter_text>Encode Non-Numerical Values to 0 and 1. Drop unnecessary columns from DataFrame and replace NaN values with 0.<jupyter_code># Categorical Features: neighbourhood_group, neighbourhood, room_type
encode_NYC_df = pd.get_dummies(df, columns = ['neighbourhood_group','room_type'])

# Dropping unnecessary features
encode_NYC_df = encode_NYC_df.drop(columns=['id', 'name', 'host_name', 
                      'last_review', 'host_id', 'neighbourhood'])

# Replace NaN with 0
encode_NYC_df['reviews_per_month']=encode_NYC_df['reviews_per_month'].replace(np.nan, 0)
encode_NYC_df['price']=encode_NYC_df['price'].replace(np.nan, 0)
# Move price to end of list
cols = encode_NYC_df.columns.tolist()
cols.append(cols.pop(cols.index('price')))
encode_NYC_df = encode_NYC_df.reindex(columns = cols)

# Sort by price
encode_NYC_df.sort_values(by='price',ascending=False,inplace=True)

encode_NYC_df.head()<jupyter_output><empty_output><jupyter_text>Split the Dataset<jupyter_code># Feature_column and encoding
feature_cols = cols
X = encode_NYC_df[feature_cols]
y = encode_NYC_df['price']

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

# Print the first 5 lines
print(X_test)
print('\n')
print(y_test)


# print the size of the traning set:
print(X_train.shape)
print(y_train.shape)

# print the size of the testing set:
print(X_test.shape)
print(y_test.shape)<jupyter_output>latitude  longitude  minimum_nights  number_of_reviews  \
45894  40.71550  -73.94656               2                  0   
20869  40.71753  -73.94946               2                  1   
38075  40.77829  -73.95093               5                  5   
11825  40.62402  -73.97071               1                  1   
41261  40.72595  -73.90299               1                 24   
...         ...        ...             ...                ...   
45273  40.70372  -73.90670               2                  1   
449    40.68288  -73.96024               3                 43   
5464   40.71305  -73.94334               6                  0   
22940  40.74530  -74.00002               3                 24   
16518  40.67323  -73.88920               3                 71   

       reviews_per_month  calculated_host_listings_count  availability_365  \
45894               0.00                               3               313   
20869               0.03                               1       [...]<jupyter_text>Random Forest Classifier<jupyter_code>## Using Random Forest Classifier with parameters: n_estimators = 19, bootstrap = True, random_state=3
my_RandomForest = RandomForestClassifier(n_estimators = 55, bootstrap = True, random_state=3, 
                                         min_samples_split = 3, min_samples_leaf =2)

my_RandomForest.fit(X_train, y_train)

y_predict_rf = my_RandomForest.predict(X_test)

print(y_predict_rf)

# calculate final accuracy
accuracy_rf = accuracy_score(y_test, y_predict_rf)

print("The accuracy is", "{:.1f}".format(accuracy_rf * 100), "%")<jupyter_output>[400  45 150 ... 200 180  39]
The accuracy is 70.0 %<jupyter_text>Linear Regression<jupyter_code># In the following line, "my_LinReg" is instantiated as an "object" of LinearRegression "class"
my_LinReg = LinearRegression()

# Fitting the model to the training dataset
my_LinReg.fit(X_train, y_train)

# Printing Theta0 using attribute "intercept_":
print(my_LinReg.intercept_)

# Printing [Theta1, Theta2, Theta3] using attribute "coef_":
print(my_LinReg.coef_)
# Predictions on the testing set
predict_price = my_LinReg.predict(X_test)

print(predict_price)


# NOT SURE IF NEEDED
# Calculating "Mean Square Error" (MSE):
# mse = metrics.mean_squared_error(y_test, predict_price)

# Using numpy sqrt function to take the square root and calculate "Root Mean Square Error" (RMSE)
# rmse = np.sqrt(mse)

# print(rmse)<jupyter_output>[595.  48. 150. ... 200. 180.  39.]<jupyter_text>Logistic Regression - WIP<jupyter_code># LOGISTIC REGRESSION NEEDS WORK, PROCESSING TAKES TOO LONG

# "my_logreg" is instantiated as an "object" of LogisticRegression "class". 
my_logreg = LogisticRegression(max_iter=10000000000000)

# Training ONLY on the training set:
my_logreg.fit(X_train, y_train)

# Testing on the testing set:
y_predict_lr = my_logreg.predict(X_test)
print(y_predict_lr)

# We can now compare the "predicted labels" for the Testing Set with its "actual labels" to evaluate the accuracy 

score_lr = accuracy_score(y_test, y_predict_lr)

print(score_lr)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09497991967871486, 'fraction_numerical': 0.0714859437751004, 'mean_word_length': 3.029935275080906, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '83805', 'license': 'MIT', 'n_tokens_mistral': 1944, 'n_tokens_neox': 1673, 'n_words': 393, 'path': '.ipynb_checkpoints/AB_NYC_Price_Prediction-checkpoint.ipynb', 'repo_name': 'KevinCrespin/NYC-Airbnb-Data-Product', 'size': '4980'}