Page 444 - AI_Ver_3.0_class_11
P. 444

# Step 3: Apply K-means clustering
                     kmeans = KMeans(n_clusters=3, random_state=42)
                     kmeans.fit(data_scaled)
                     # Add the cluster labels to the data
                     data['Cluster'] = kmeans.labels_
                     # Step 4: Visualize the clusters
                     plt.figure(figsize=(10, 6))
                     plt.scatter(data['Annual         Income'],     data['Loan     Amount'],     c=data['Cluster'],
                     cmap='viridis')
                     plt.xlabel('Annual Income')
                     plt.ylabel('Loan Amount')
                     plt.title('K-means Clustering of Loan Applicants')
                     plt.colorbar(label='Cluster')
                     plt.show()
                   Output:























              (Explanation: The above program will generate synthetic data for 100 loan applicants with two features: ‘Annual Income’
              and ‘Loan Amount’. We use np.random.normal to generate normal distributions for these features. StandardScaler is
              used to standardize the features to ensure they have a mean of 0 and a standard deviation of 1. Then we initialize and
              fit the K-means algorithm with 3 clusters. Lastly, we create a scatter plot of ‘Annual Income’ vs. ‘Loan Amount’, coloured
              by cluster assignment.)
              26.  Create a simple chatbot using Python (or botisfy.com) to counsel students suffering from exam related stress.

                     import random
                     print("Hello!  I'm  here  to  help  you  with  your  exam  stress.  How  are  you  feeling
                     today?")
                     while True:
                         user_input = input("> ")
                         if user_input.lower() in ["exit", "bye", "quit"]:
                             print("Goodbye! Remember to stay calm and take breaks. You've got this!")

                             break
                         elif "stressed" in user_input.lower() or "anxious" in user_input.lower():
                              print("It's normal to feel stressed before exams. Just remember to take
                               deep breaths.")
                         elif "tired" in user_input.lower() or "exhausted" in user_input.lower():


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