Built KNN from scratch using Pandas and Numpy
- Two datasets are imported from CSV files: one for the main dataset (
CO2_Emissions.csv) and the other for prediction (CO2_prediction.csv).
- Initial data preprocessing tasks are executed, including dropping unnecessary columns and checking for missing values.
- The dataset is separated into numerical and categorical features for further processing.
- Data transformation techniques are applied, including scaling numerical features using MinMaxScaler and label encoding for categorical features using LabelEncoder.
- The scaled numerical and encoded categorical features are concatenated into a single dataframe, preparing the data for modeling.
- The data is split into training and test sets to evaluate the performance of the machine learning models.
- A K-Nearest Neighbors (KNN) regression model is implemented using both a custom KNN implementation and the scikit-learn KNN model.
- The models are trained and evaluated using different values of
k(number of neighbors), and mean squared errors are calculated for both training and test data.
- The performance of the custom KNN implementation is compared with the scikit-learn KNN model by calculating the mean squared errors (MSE) for their predictions.
- Based on the MSE values, it is found that the custom KNN implementation has a lower MSE, indicating better performance compared to the scikit-learn KNN model.