Saturday, 16 March 2024

Text to Vector , Preprocessing and Loading to mode

 Hi

import nltk
from nltk.corpus import stopwords
from nltk.stem.porter import PorterStemmer
import pandas as pd
import re


nltk.download('stopwords')
port_stem = PorterStemmer()
def stemming(content):
    stemmed_content = re.sub('[^a-zA-Z]',' ',content)
    stemmed_content = stemmed_content.lower()
    stemmed_content = stemmed_content.split()
    stemmed_content = [port_stem.stem(word) for word in stemmed_content if not word in stopwords.words('english')]
    stemmed_content = ' '.join(stemmed_content)
    return stemmed_content

hupstr=input('Enter the tweet')
df1 = pd.DataFrame({'text': [hupstr]})
df1['text']  = df1['text'].apply(stemming)

from keras.models import load_model
hupmodel= load_model("hupmodel17.h5")


loaded_vectorizer = joblib.load('huptokenizer.joblib')
X2 = loaded_vectorizer.texts_to_sequences(df1['text'])
X2 = pad_sequences(X2,maxlen=337)

#X_test_transformed = loaded_vectorizer.transform(hupinput)
#X_test_dense = X_test_transformed.toarray()
hupprediction1 = hupmodel.predict_on_batch(np.stack(X2))
labelencoder = joblib.load('huplabelencoder.pkl')
huplabel1 = labelencoder.inverse_transform(np.argmax(hupprediction1, axis=1))
hupresult1 = ''.join(huplabel1)
print(hupresult1)

Print Tensorflow version

 Hi 

Try this


import tensorflow as tf print(tf.__version__) import keras print(keras.__version__)

Tuesday, 12 March 2024

How Flask file shows templates and images

 Hi

Normal Flask code look like

--------------

from flask import Flask, redirect, url_for, request
app = Flask(__name__)
 
 
@app.route('/success/<name>')
def success(name):
    return 'Hi %s' % name
 
 
@app.route('/login', methods=['POST', 'GET'])
def login():
    if request.method == 'POST':
        user = request.form['name']
        return redirect(url_for('success', name=user))
    else:
        user = request.args.get('name')
        return redirect(url_for('success', name=user))
 
 
if __name__ == '__main__':
    app.run(debug=True)

--------------

If you need template page, your flask file should return the following code

return render_template('template.html', result=hupresult)

Your template.html should be saved inside templates folder

and the code template.html should look like


<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Flask Image Example</title>

</head>

<body>

    <h1>{{ result }}</h1>


    <!-- Display the image from the static folder -->

    <img src="{{ url_for('static', filename='bg.jpg') }}" alt="Your Image">

</body>

</html>


The image bg.jpg should be saved inside 'static' folder


Tuesday, 5 March 2024

Face Emotion Detection - Colab

 Hi all

Step1 : Open the colab

Step2 : File -> Save a copy in Drive

Step3 : Work with the copy

Link

https://colab.research.google.com/drive/1K-XhE_qW0VLWrPmjycz8kriRYmA77M33?usp=sharing

Face emotion dataset

 Hi all


https://drive.google.com/drive/folders/1PaAA1P_5O8bNV42AHxNEHyzmQuMsR3kW?usp=sharing

DIST Google form outputs

 Hi all

Please upload these screenshots

1. Python program without ML for sentiment analysis

2. using SET option 

3. Using ML for sentiment analysis

4. Graph showing algorithm performance - 7 agorithms

5. Use of Pickle

6. Use of Savemodel

7. Covid data analysis - Using ML for sentiment analysis

8. Deep learning - Face emotion recognition 

9. Flask Basics



Monday, 4 March 2024

Show graph in Python for Test accuracy and Train accuracy o various ML algorithms

 Hi all,

Please see the code.


import matplotlib.pyplot as plt

import numpy as np


# Example data (replace this with your actual data)

algorithms = ['KNN', 'ANN', 'Decision Tree', 'Ada Boost', 'Random forest', 'Naive Bayes', 'Log Regression']

test_accuracies = [0.85, 0.92, 0.78, 0.88, 0.95, 0.89, 0.91]

train_accuracies = [0.95, 0.97, 0.88, 0.93, 0.98, 0.92, 0.96]


# Set up bar positions

bar_width = 0.35

index = np.arange(len(algorithms))


# Create bar chart

fig, ax = plt.subplots()

bar1 = ax.bar(index, test_accuracies, bar_width, label='Test Accuracy')

bar2 = ax.bar(index + bar_width, train_accuracies, bar_width, label='Train Accuracy')


# Add labels, title, and legend

ax.set_xlabel('Machine Learning Algorithms')

ax.set_ylabel('Accuracy')

ax.set_title('Test and Train Accuracies of Machine Learning Algorithms')

ax.set_xticks(index + bar_width / 2)

ax.set_xticklabels(algorithms)

ax.legend()


# Show the plot

plt.show()


Deploy ML Model using input from user

 Hi,

Please find the code


data=[]
marks=int(input("enter your marks"))
data.append(marks)
maths=int(input("enter marks for maths"))
data.append(maths)
qa=int(input("enter marks for qa"))
data.append(qa)
pg=int(input("enter marks for programing"))
data.append(pg)
ndata=[]
ndata.append(data)
result=knn.predict(ndata)
if(result==0):
  print("not placed")
else:
  print("placed")

Deploy model

 Hi,

Please find the code


input1=[[60,80,90,6]]
result=knn.predict(input1)
print(result)

Shared Datasets

 Hi,

Please find the shared dataset.


https://drive.google.com/drive/folders/1Ht32d3wP-lIJ4QrZsjQHFwU_hnGal0YI?usp=sharing