0% found this document useful (0 votes)
23 views3 pages

SVM Regression and Classification Tasks

The document describes three questions for an assignment involving machine learning techniques: 1. Build an SVM regression model to predict used car prices based on age and mileage using a provided dataset. 2. Implement an SVM classifier to classify CIFAR-10 images into classes, evaluating performance on test data. 3. Create an SVR model to predict stock prices using historical data merged with news data, evaluating the model's performance on test data.

Uploaded by

vedantsimp
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

SVM Regression and Classification Tasks

The document describes three questions for an assignment involving machine learning techniques: 1. Build an SVM regression model to predict used car prices based on age and mileage using a provided dataset. 2. Implement an SVM classifier to classify CIFAR-10 images into classes, evaluating performance on test data. 3. Create an SVR model to predict stock prices using historical data merged with news data, evaluating the model's performance on test data.

Uploaded by

vedantsimp
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ASSIGNMENT 2

Q1. SVM Regression (3 Points)

You are given a dataset that contains information about the prices of used cars based on their age
and mileage. Your goal is to build an SVM regression model to predict the prices of cars. You need to
perform the following tasks:

1. Data Exploration:

• Load and explore the dataset.


• Visualize the data to understand the relationship between age, mileage, and car prices.

2. Data Preprocessing:

• Split the dataset into training and testing sets.


• Standardize the features (age and mileage) to have zero mean and unit variance.

3. SVM Regression:

• Train an SVM regression model using a linear kernel.


• Tune the hyperparameters (e.g., C, epsilon) using cross-validation or grid search to find the
best model.

4. Model Evaluation:

• Evaluate the model's performance on the testing set using appropriate regression metrics
(e.g., Mean Absolute Error, Mean Squared Error, R-squared).
• Visualize the model's predictions against the actual car prices.

5. Discussion:

• Discuss the results and the impact of hyperparameter tuning on the model's performance.
• Compare the SVM regression model with other regression techniques (e.g., linear
regression, decision tree regression) in terms of predictive accuracy.

6. Conclusion:

• Summarize your findings and provide insights into the key factors that influence used car
prices based on your SVM regression model.

Additional Information:

The dataset is provided in a CSV file containing columns for "Age," "Mileage," and "Price." You can
use Python and relevant libraries (e.g., scikit-learn) for data analysis, modelling, and visualization.
Make sure to provide code, plots, and explanations for each step in your assignment. Please ensure
to submit a well-documented report that includes code, visualizations, and a detailed explanation of
your approach and findings.
Q2. Implement SVM Classifier (3 Points)
Implement an SVM classifier to classify images from the CIFAR-10 dataset into their
respective classes.
Instructions:

• Dataset Loading: Load the CIFAR-10 dataset. You can access this dataset using
popular deep learning libraries like PyTorch or TensorFlow, or download it from the
CIFAR-10 website.

• Data Preprocessing: Preprocess the dataset by normalizing the images and flattening
them into feature vectors. (Extra Credit: Augment additional images to the dataset
using flipping and rotation). Split the dataset into training and testing sets in the ratio
80:20 using stratified sampling.

• Feature Extraction: Implement feature extraction techniques if needed. For eg:


perform Principal Component Analysis (PCA) for dimensionality reduction.

• SVM Classifier Implementation:


1. Implement a linear SVM classifier using a library like Scikit-Learn. Train the
classifier on the training dataset. Tune the hyperparameters of the classifier by
changing the value of C = [1,10, 100].
2. Implement an SVM classifier with RBF kernel. Train the classifier on the training
dataset. Tune the hyperparameters of the classifier by changing the values of 𝛾 =
[10−3 , 10−4 ], C= [1,10,100].

• Model Evaluation: Evaluate the performance of both SVM classifier on the test
dataset using classification metrics such as accuracy, precision, recall, and F1-score.

• Visualization: Visualize some example images that were correctly classified and some
that were misclassified to understand the model's performance.

• Write a Report: Create a report based on your findings.

Q3. Support Vector Regression (SVR) -based stock price prediction with the influence of
news events in Python (4 Points)

Instructions:
1. Obtain API Key:
• Go to the News API website.
• Sign up for an account to obtain your API key.
• Replace "your_news_api_key_here" in the code with your actual News API
key.
2. Download Historical Stock Data:
• Use the yfinance library to download historical stock price data for a chosen
company. For this assignment, we will focus on Apple Inc. (AAPL) stock.
• Set the start and end dates for data retrieval (e.g., start_date = "2022-10-31",
end_date = "2023-10-31").
3. Download News Data:
• Utilize the NewsApiClient from the newsapi-python library to retrieve news
articles related to the chosen company.
• Specify the company name and date range for news data retrieval.
4. Data Merging:
• Merge the stock data and news data based on the publication date.
5. Feature Engineering:
• Create a new feature based on news sentiment or other relevant information
extracted from the news articles.
6. Data Splitting:
• Split the dataset into training and testing sets (e.g., 80% training, 20%
testing).
7. Model Building:
• Build an SVR model (Support Vector Regression) from scratch with the 'rbf'
kernel.
8. Model Training and Evaluation:
• Train the SVR model on the training data and make predictions of Adjusted
closing price and Opening price of next 30 days.
• Evaluate the model's performance using metrics like Mean Absolute Error
(MAE), Mean Squared Error (MSE), and R-squared (R^2).
• Build a pickle file of the model and run this for three different companies.
9. Assignment Submission:
• Submit the Python code along with any relevant comments or explanations of
the code. Also make a report on the same.

DEADLINE FOR SUBMISSION IS 13 NOVEMBER 11.59 PM.

Common questions

Powered by AI

Key preprocessing steps include splitting the dataset into training and testing sets to enable model evaluation, and standardizing features like age and mileage to ensure they have zero mean and unit variance. These steps are crucial as they ensure the model has balanced input for training, reducing biases associated with differing scales among features. Without standardization, SVM can be skewed by features with larger ranges .

Normalization benefits SVM models by scaling pixel values to a similar range, thereby facilitating more stable and faster convergence during training. It also enhances the model's sensitivity to subtle features across images. However, challenges include the risk of losing important information or details if not implemented thoughtfully, which may lead to decreased performance. Furthermore, improperly normalized data can hinder the model's ability to differentiate between closely related classes .

SVM regression typically offers superior predictive accuracy over linear regression due to its ability to capture non-linear patterns through kernel trick, especially when using RBF kernel. Compared to decision trees, SVMs often generalize better as they avoid overfitting through margin maximization. Decision trees might perform well on smaller datasets or when capturing complex interactions but could be less robust to extrapolating test data, affecting overall predictive accuracy for unseen samples .

PCA, as a dimensionality reduction technique, plays a pivotal role in the feature extraction process by transforming high-dimensional image data into lower-dimensional space, capturing most variance with fewer components. This simplification aids in minimizing computational cost and enhancing SVM classifier performance by reducing noise and redundancy, leading to more efficient learning and potentially higher classification accuracy on complex datasets like CIFAR-10 .

Visualizing correctly classified and misclassified images allows for an in-depth analysis of the model's strengths and weaknesses. By identifying patterns in misclassified images, such as similarity to other classes or poor contrast, insights can be gained into potential data preprocessing improvements or feature extraction techniques that could enhance accuracy. Moreover, visualization aids in comprehending the classifier's decision boundaries and can highlight biases in the data or model .

Hyperparameter tuning, which involves adjusting parameters such as C and epsilon in SVM regression, directly influences the model's complexity and generalization ability. A well-tuned model can balance bias-variance trade-off, thus improving predictive accuracy on unseen data. For instance, a high C value allows for lower bias but can result in overfitting, whereas the right level can enhance the model's performance by capturing significant patterns in the dataset while avoiding noise .

The radial basis function (rbf) kernel enables SVR models to handle non-linear relationships by mapping input features into higher-dimensional spaces. This capability is crucial for stock price prediction, where linear models may fall short due to the complex, non-linear interactions between various factors affecting prices. The flexibility afforded by the rbf kernel allows models to better capture intricate patterns in the data, enhancing predictive accuracy and robustness .

Stratified sampling ensures each class is represented proportionally in both training and test datasets, which is critical for maintaining balanced representation of classes and improving classifier performance. This prevents class imbalance, which can skew the training process, leading to biased models that perform well on majority classes but poorly on minority classes. Consequently, it delivers a more robust evaluation of the classifier's true performance across different classes .

Feature engineering, such as the integration of news sentiment into stock price prediction, allows the SVM model to incorporate qualitative data that might reflect real-world market dynamics. For example, transforming sentiment from news articles into a quantitative metric can provide context on the market mood affecting stock prices, thus enhancing the model's accuracy in predictions. This approach helps capture intrinsic patterns and correlations between external factors and stock movements beyond pure historical price data .

An effective combination involves aligning stock price data with corresponding news sentiment scores through temporal merging, ensuring each stock data entry between period intervals has associated sentiment features. Feature engineering can encompass both lagged sentiment effects and rolling sentiment averages to express immediate and long-term news impacts. Effective combination requires careful date alignment to ensure causality and may involve utilizing natural language processing techniques to quantify sentiment accurately .

You might also like