AI Lab 2nd Intenal.
AI Lab 2nd Intenal.
import numpy as np
import pandas as pd
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
from sklearn.metrics import classification_report
def importdata():
balance_data = pd.read_csv(
'balance-scale.data',
sep= ',', header = None)
def main():
data = importdata()
X, Y, X_train, X_test, y_train, y_test = splitdataset(data)
clf_gini = train_using_gini(X_train, X_test, y_train)
clf_entropy = tarin_using_entropy(X_train, X_test, y_train)
print("Results Using Gini Index:")
Implement stemming:
Python program:
Game bot:
def generate_number():
return random.randint(1, 100)
def play_game():
number_to_guess = generate_number()attempts = 0
print("Welcome to the Guessing Game!")
print("I have chosen a number between 1 and 100. Try to guessit.")
while True:
guess = input("Enter your guess (or 'exit' to quit): ")
if guess.lower() == "exit":
print("The number was:", number_to_guess)
print("Thanks for playing! Goodbye!")
break
try:
guess = int(guess)
attempts += 1
if guess < number_to_guess:
print("Too low! Try again.")
elif guess > number_to_guess:
print("Too high! Try again.")
else:
print(f"Congratulations! You guessed the number in {attempts}
attempts.")
break
except ValueError:
print("Invalid input. Please enter a number.")
play_game()
Output:
Welcome to the Guessing Game!
I have chosen a number between 1 and 100. Try to guess it.
Enter your guess (or 'exit' to quit): 35
Chat bot
!pip install nltk
import nltk
from nltk.chat.util import Chat, reflections
pairs = [
[
r"my name is (.
)",
["Hello %1, how can I help you today?",]
],
[
r"what is your name?",
["My name is ChatBot and I'm here to assist you.",]
],
[
r"how are you ?",
["I'm doing well, thank you!", "I am always here to help.",]
],
[
r"sorry (.
)",
["No problem, please tell me how can I assist you?",]
],
Output:
Requirement already satisfied: nltk in /usr/local/lib/python3.10/distpackages (3.8.1)
Requirement already satisfied: click in
/usr/local/lib/python3.10/dist-packages (from nltk) (8.1.7) Requirement
already satisfied: joblib in /usr/local/lib/python3.10/dist-packages
(from nltk) (1.3.2) Requirement already satisfied: regex>=2021.8.3 in
/usr/local/lib/python3.10/dist-packages (from nltk) (2023.12.25)
Requirement already satisfied: tqdm in /usr/local/lib/python3.10/distpackages
(from nltk) (4.66.1)
Hi! I'm ChatBot. How can I assist you today?