Data analytics
Data analytics
Data analytics
import numpy as np
import pandas as pd
data = pd.read_csv('C:/Users/HP/Desktop/data1.csv')
regressor = LinearRegression()
regressor.fit(X_train, Y_train)
Y_pred = regressor.predict(X_test)
plt.title('Linear Regression')
plt.xlabel('X (Input)')
plt.ylabel('Y (Output)')
plt.legend()
plt.show()
# Output predicted values
Output
import numpy as np
import pandas as pd
df = pd.read_csv('C:/Users/HP/Desktop/data2.csv')
X = df[['Feature1', 'Feature2']].values
# Number of clusters
k=3
kmeans.fit(X)
y_kmeans = kmeans.predict(X)
# Plot centroids
plt.title('K-Means Clustering')
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.legend()
plt.show()
Output
Exp 3 (Logistic Regression)
import numpy as np
import pandas as pd
data = pd.read_csv('C:/Users/HP/Desktop/data3.csv')
classifier = LogisticRegression()
classifier.fit(X_train, Y_train)
Y_pred = classifier.predict(X_test)
# Calculate Accuracy
plt.title('Logistic Regression')
plt.xlabel('X (Input)')
plt.ylabel('Probability/Output')
plt.legend()
plt.show()
print("Accuracy:", accuracy)
Output
Accuracy: 0.0
Exp 2 (Multiple Linear Regression)
import pandas as pd
import numpy as np
df = pd.read_csv('C:/Users/HP/Desktop/data4.csv')
regressor = LinearRegression()
regressor.fit(X_train, Y_train)
Y_pred = regressor.predict(X_test)
plt.xlabel('Actual values')
plt.ylabel('Predicted values')
plt.legend()
plt.show()
Output
import pandas as pd
df = pd.DataFrame(data)
te = TransactionEncoder()
te_ary = te.fit(df['Items']).transform(df['Items'])
print("Frequent Itemsets:")
print(frequent_itemsets)
print("\nAssociation Rules:")
print(rules)
Output