<jupyter_start><jupyter_text><jupyter_code>import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression, RANSACRegressor
housing_data = pd.read_fwf("https://archive.ics.uci.edu/ml/machine-learning-databases/housing/housing.data", header=None)
housing_data.columns =["crime_rate", "zoned_land", "industry", "bounds_river", "nox_conc", "rooms", "age", "distance", "highways", "tax", "pt_ratio", "b_estimator", "pop_stat", "price"]
housing_data_input = housing_data.drop('price', axis=1)
housing_data_output = housing_data.price
model = LinearRegression()
model.fit(housing_data_input, housing_data_output)
model.score(housing_data_input, housing_data_output)
ransac = RANSACRegressor(LinearRegression(), min_samples=50, max_trials=100, residual_threshold=5.0)
ransac.fit(housing_data_input, housing_data_output)
inliers = housing_data_input[ransac.inlier_mask_]
outliers = housing_data_input[~ransac.inlier_mask_]
print(ransac.score(inliers, housing_data_output[ransac.inlier_mask_]))
print(ransac.score(outliers, housing_data_output[~ransac.inlier_mask_]))
import matplotlib.pyplot as plt
plt.scatter(inliers.rooms, housing_data_output[ransac.inlier_mask_], label = "inliers")
plt.scatter(outliers.rooms, housing_data_output[~ransac.inlier_mask_], label = "outliers")
plt.legend()
plt.xlabel("Rooms")
plt.ylabel("Price")
plt.show()
from sklearn.preprocessing import PolynomialFeatures
polynomial_features = PolynomialFeatures(2, interaction_only=False)
polynomial_input = polynomial_features.fit_transform(housing_data_input)
polynomial_model = LinearRegression()
polynomial_model.fit(polynomial_input, housing_data_output)
# 2 -> 0.8863751179612701
# 3 -> 0.9989291660161697
polynomial_model.score(polynomial_input, housing_data_output)
polynomial_model.coef_.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11848601206801974, 'fraction_numerical': 0.024684585847504114, 'mean_word_length': 10.617834394904458, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '82098', 'license': 'MIT', 'n_tokens_mistral': 711, 'n_tokens_neox': 645, 'n_words': 93, 'path': '2_Linear_And_Logistic_Regression/LinearLogisticRegresionRANSAC.ipynb', 'repo_name': 'vladiant/SoftUniMachineLearning2019', 'size': '1823'}