Screen.Recording.2024-07-20.101427.mp4
This project is a web application designed to predict laptop prices based on various features such as brand, processor type, RAM, storage, and more. The application uses machine learning models to provide predictions and offers a user-friendly interface for interacting with the model.
The project is organized into several components:
- Data Collection: The dataset used for training the model.
- Data Preprocessing: Steps to clean and prepare the data for modeling.
- Model Training: Training and evaluating machine learning models.
- Web Application: Implementation of the web interface using Flask.
- Deployment: Instructions for running the application locally or deploying it.
The dataset used for this project contains information about laptop specifications and their prices. It includes features such as:
- Brand
- Processor Type
- RAM
- Storage Type and Size
- Display Size
- Operating System
- Weight
The dataset is sourced from [insert source if applicable].
The data is loaded into a DataFrame using pandas:
import pandas as pd
data = pd.read_csv('path_to_your_dataset.csv')
Missing values are handled by:
- Dropping rows with missing target values (prices).
- Imputing missing values in categorical features with the mode.
data = data.dropna(subset=['Price'])
data['RAM'] = data['RAM'].fillna(data['RAM'].mode()[0])
- Extracting Numeric Values: Convert features like 'RAM' and 'Storage' to numeric values.
data['RAM'] = data['RAM'].str.extract('(\d+)').astype(int)
data['Storage'] = data['Storage'].str.extract('(\d+)').astype(int)
- Encoding Categorical Features: Use one-hot encoding for categorical features like 'Brand' and 'Processor Type'.
data = pd.get_dummies(data, columns=['Brand', 'Processor Type'])
The data is split into training and testing sets:
from sklearn.model_selection import train_test_split
X = data.drop('Price', axis=1)
y = data['Price']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
For this project, we used a Random Forest Regressor due to its effectiveness in handling tabular data with various features.
from sklearn.ensemble import RandomForestRegressor
model = RandomForestRegressor(n_estimators=100, random_state=42)
model.fit(X_train, y_train)
Evaluate the model's performance using metrics like Mean Absolute Error (MAE) and R-squared.
from sklearn.metrics import mean_absolute_error, r2_score
y_pred = model.predict(X_test)
mae = mean_absolute_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)
print(f'Mean Absolute Error: {mae}')
print(f'R-squared: {r2}')
Flask is used to create a web interface for the application.
from flask import Flask, request, render_template
import joblib
app = Flask(__name__)
model = joblib.load('model.pkl')
- Home Route: Renders the main page.
@app.route('/')
def home():
return render_template('index.html')
- Prediction Route: Handles form submissions and returns predictions.
@app.route('/predict', methods=['POST'])
def predict():
features = [float(x) for x in request.form.values()]
prediction = model.predict([features])
return render_template('result.html', prediction=prediction[0])
- index.html: Form for user input.
<!DOCTYPE html>
<html>
<head>
<title>Laptop Price Prediction</title>
</head>
<body>
<h1>Enter Laptop Details</h1>
<form action="/predict" method="post">
<!-- Form Fields for Features -->
<input type="submit" value="Predict">
</form>
</body>
</html>
- result.html: Displays the prediction result.
<!DOCTYPE html>
<html>
<head>
<title>Prediction Result</title>
</head>
<body>
<h1>Predicted Price: {{ prediction }}</h1>
</body>
</html>
- Install dependencies:
pip install -r requirements.txt
- Run the Flask application:
python app.py
- Create a
Procfile
:
web: python app.py
- Follow Heroku deployment steps:
- Create a Heroku account.
- Install Heroku CLI.
- Run
heroku create
. - Deploy the app using
git push heroku master
.
Feel free to contribute to the project by submitting issues or pull requests.
This project is licensed under the MIT License.
- [Insert any acknowledgments or credits here]
Let me know if you need any more details or adjustments!