Wednesday, May 24, 2023

Create a Decision Tree Chart in R Language based on One Variable

--The Data is in Excel file, first we are installing required libraries, if not already done.

--Our Target variable is Income, here in this code example.


install.packages("rpart")

install.packages("rpart.plot")

install.packages("readxl")


library(rpart)

library(rpart.plot)

library(readxl)


data = read_excel("C:\\Users\\Khan\\Downloads\\customer_dbase (1).xlsx")


selected_data <- customer_dbase[, c("age", "income")]


tree_model <- rpart(income ~ ., data = selected_data)


rpart.plot(tree_model)

Monday, May 15, 2023

Python Word Cloud

 #Use below Simple Python Code to create Word Cloud Chart based on text saved in a TXT File

#Replace File path in below code

#Replace or Add the stop words that you want to remove along standard stop words

#Change the Max words (from current 30) as per your need


from wordcloud import WordCloud, STOPWORDS

import matplotlib.pyplot as plt

file = open(r"C:\Users\Khan\Desktop\stopwords.txt", errors='ignore')

text = file.read()

stopwords = set(STOPWORDS)

stopwords.update(["drink", "now", "wine", "flavor", "flavors"])

wordcloud = WordCloud(max_words=30, stopwords = stopwords, background_color="white").generate(text)

plt.imshow(wordcloud, interpolation='bilinear')

plt.axis("off")

plt.show()