Da Programs
Da Programs
def word_count(file_path):
word_counts = {}
try:
text = file.read()
words = text.split()
if word in word_counts:
word_counts[word] += 1
else:
word_counts[word] = 1
return word_counts
except FileNotFoundError:
return None
# Example usage
file_path = 'example.txt' # Replace this with the path to your text file
word_counts = word_count(file_path)
print(f"{word}: {count}")
OUTPUT
import pandas as pd
df = pd.read_csv('weather.csv')
# Print the DataFrame to see the content
print(df)
output
iris = datasets.load_iris()
# Take the first two features. We could avoid this by using a two-dim dataset
X = iris.data[:, :2]
y = iris.target
# we create an instance of SVM and fit out data. We do not scale our
models = (
svm.SVC(kernel="linear", C=C),
svm.LinearSVC(C=C, max_iter=10000),
titles = (
plt.subplots_adjust(wspace=0.4, hspace=0.4)
disp = DecisionBoundaryDisplay.from_estimator(
clf,
X,
response_method="predict",
cmap=plt.cm.coolwarm,
alpha=0.8,
ax=ax,
xlabel=iris.feature_names[0],
ylabel=iris.feature_names[1],
ax.set_xticks(())
ax.set_yticks(())
ax.set_title(title)
plt.show()
data = load_iris()
X = data.data # Features
y = data.target # Labels
# Create and train the Decision Tree Classifier with optimized hyperparameters
clf = DecisionTreeClassifier(
random_state=42
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
print("Accuracy:", accuracy)
plt.figure(figsize=(12, 8))
plt.show()
4. Visualize data using any plotting framework
import pandas as pd
data = load_iris()
df = pd.DataFrame(data.data, columns=data.feature_names)
df['species'] = data.target
plt.show()
plt.figure(figsize=(8, 6))
plt.show()
plt.figure(figsize=(10, 6))
plt.title("Boxplot of Features")
plt.show()
plt.figure(figsize=(8, 6))
sns.scatterplot(
data=df,
hue='species',
style='species',
palette='deep',
s=100