Page 443 - AI Ver 3.0 Class 11
P. 443

plt.legend()
                        plt.savefig("Linear_Regression.png")
                        plt.show()
                     Output:
                        First 10 actual prices vs predicted prices:
                        Actual: 28999, Predicted: 33461.01675564506
                        Actual: 30999, Predicted: 32409.481421638382
                        Actual: 72999, Predicted: 23646.686971582698
                        Actual: 27990, Predicted: 35914.599201660654
                        Actual: 11990, Predicted: 32409.481421638382
                        Actual: 39990, Predicted: 46429.95254172747
                        Actual: 56990, Predicted: 39419.71698168293
                        Actual: 8199, Predicted: 32409.481421638382
                        Actual: 59999, Predicted: 36790.87864666622
                        Actual: 10999, Predicted: 32409.481421638382






















                 25.   Write Python program for K Means Clustering Algorithm. You may generate synthetic data for 100 loan applicants
                     with two features: ‘Annual Income’ and ‘Loan Amount’.
                        import numpy as np
                        import pandas as pd
                        import matplotlib.pyplot as plt
                        from sklearn.cluster import KMeans
                        from sklearn.preprocessing import StandardScaler
                        # Step 1: Create synthetic data
                        np.random.seed(42)
                        num_applicants = 100
                        # Assume we have two features: 'Annual Income' and 'Loan Amount'
                        annual_income = np.random.normal(loc=50000, scale=15000, size=num_applicants)
                        loan_amount = np.random.normal(loc=20000, scale=7000, size=num_applicants)
                        # Combine into a DataFrame
                        data = pd.DataFrame({
                            'Annual Income': annual_income,
                            'Loan Amount': loan_amount             })
                        # Step 2: Standardize the data
                        scaler = StandardScaler()
                        data_scaled = scaler.fit_transform(data)

                                                                                          Practical Questions   441
   438   439   440   441   442   443   444   445   446   447   448