Page 442 - AI Ver 3.0 Class 11
P. 442

22.  Find the Transpose of the following matrix.
                                                             2     –5     3
              Ans.      2     –1                             –1    0     2/5
                        –5    0
                        3     2/5

              23.  Find the sum of A and B.

                           16   –10             6    2
              Ans.    A =   5       0      B =   –10  8
                           16   –10     6    2
                   A + B =   5       0   +   –10  8

                           22   –8
                        =  –5     8
              24.   Perform Linear Regression on the Mobile Phone Price Prediction (The dataset can be downloaded
                   from  https://www.kaggle.com/datasets/dewangmoghe/mobile-phone-price-prediction save the
                   file in csv format by the name of “mobile phone price prediction”. Also display few records of the
                   y-predict variable of testing dataset after linear regression has been performed.

                     import pandas as pd
                     from sklearn.model_selection import train_test_split
                     from sklearn.linear_model import LinearRegression
                     import matplotlib.pyplot as plt
                     # Load the dataset
                     data = pd.read_csv('mobile phone price prediction.csv')
                     # Extract numerical values from the 'Battery' and 'Price' columns
                     data['Battery'] = data['Battery'].str.extract('(\d+)').astype(int)
                     data['Price'] = data['Price'].str.replace(',', '').astype(int)
                     # Select the feature and target variable
                     X = data[['Battery']]  # Feature: Battery
                     y = data['Price']      # Target: Price
                     # Split the data into training and testing sets
                     X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_
                     state=42)
                     # Create and train the linear regression model
                     model = LinearRegression()
                     model.fit(X_train, y_train)
                     # Predict the target variable for the testing set
                     y_pred = model.predict(X_test)
                     # Print the first 10 rows of the actual and predicted values
                     print("First 10 actual prices vs predicted prices:")
                     for actual, predicted in zip(y_test[:10], y_pred[:10]):
                         print(f"Actual: {actual}, Predicted: {predicted}")
                     # Plot the results
                     plt.scatter(X_test, y_test, color='blue', label='Actual prices')
                     plt.plot(X_test, y_pred, color='red', label='Predicted prices')
                     plt.xlabel('Battery Power (mAh)')
                     plt.ylabel('Price (INR)')
                     plt.title('Battery Power vs. Price')

                    440     Touchpad Artificial Intelligence (Ver. 3.0)-XI
   437   438   439   440   441   442   443   444   445   446   447