├── LICENSE ├── README.md └── Regression_House Pricing.ipynb Analysis /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 mahdieslaminet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MachineLearningProjects -------------------------------------------------------------------------------- /Regression_House Pricing.ipynb Analysis: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | from sklearn.linear_model import LinearRegression 4 | from sklearn.preprocessing import PolynomialFeatures 5 | from sklearn.metrics import mean_squared_error, r2_score 6 | 7 | # داده‌ها (اندازه خانه و قیمت آن) 8 | sizes = np.array([500, 750, 1000, 1250, 1500, 1750, 2000, 2250, 2500]).reshape(-1, 1) 9 | prices = np.array([150, 220, 250, 270, 290, 310, 320, 330, 340]) 10 | 11 | # رگرسیون خطی 12 | linear_model = LinearRegression() 13 | linear_model.fit(sizes, prices) 14 | linear_predictions = linear_model.predict(sizes) 15 | 16 | # رگرسیون درجه دوم 17 | poly = PolynomialFeatures(degree=2) 18 | sizes_poly = poly.fit_transform(sizes) 19 | poly_model = LinearRegression() 20 | poly_model.fit(sizes_poly, prices) 21 | poly_predictions = poly_model.predict(sizes_poly) 22 | 23 | # ارزیابی مدل‌ها 24 | linear_mse = mean_squared_error(prices, linear_predictions) 25 | linear_r2 = r2_score(prices, linear_predictions) 26 | poly_mse = mean_squared_error(prices, poly_predictions) 27 | poly_r2 = r2_score(prices, poly_predictions) 28 | 29 | # نمایش نتایج 30 | print("Linear Regression:\n") 31 | print(f"MSE: {linear_mse:.2f}, R2: {linear_r2:.2f}\n") 32 | print("Polynomial Regression (Degree 2):\n") 33 | print(f"MSE: {poly_mse:.2f}, R2: {poly_r2:.2f}\n") 34 | 35 | # مصورسازی 36 | plt.figure(figsize=(10, 6)) 37 | plt.scatter(sizes, prices, color='red', label='Actual Data') 38 | plt.plot(sizes, linear_predictions, color='blue', label='Linear Regression') 39 | plt.plot(sizes, poly_predictions, color='green', label='Polynomial Regression (Degree 2)') 40 | plt.title("House Pricing: Linear vs Polynomial Regression") 41 | plt.xlabel("Size (sq ft)") 42 | plt.ylabel("Price (1000$)") 43 | plt.legend() 44 | plt.grid(True) 45 | plt.show() 46 | --------------------------------------------------------------------------------