D3 docs
D3 docs
-- ROLL-UP operation: group by edition and count the number of books for each
SELECT edition, COUNT(*) AS num_books
FROM books
GROUP BY edition;
PAGE RANK
import numpy as np
def main():
n = int(input("Enter the number of pages: "))
links = np.array([list(map(int, input(f"Row {i + 1}: ").split())) for i in range(n)])
ranks = page_rank(n, links)
print("\nPageRank Values:")
for i, rank in enumerate(ranks, 1):
print(f"Page {i}: {rank:.6f}")
if __name__ == "__main__":
main()
//DECISION TREE----------------------------------------------------------------------------------
import pandas as pd
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
data = load_iris()
df = pd.DataFrame(data.data, columns=data.feature_names)
df['target'] = data.target
print("Dataset:")
print(df.head())
X = df.drop(columns=['target'])
y = df['target']
classifier = DecisionTreeClassifier()
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
class Itemset:
def __init__(self, itemset):
self.itemset = itemset
self.count = 0
def get_user_input():
transactions = []
for _ in range(int(input("Enter the number of transactions: "))):
items = list(map(int, input("Enter items (comma-separated): ").split(',')))
transactions.append(Transaction(items))
return transactions
transactions = get_user_input()
min_support = int(input("Enter the minimum support (e.g., 2): "))
apriori(transactions, min_support)
OUTPUT:-------
Enter the number of transactions: 5
Enter items (comma-separated): 1,2
Enter items (comma-separated): 1
Enter items (comma-separated): 2
Enter items (comma-separated): 1,2,3
Enter items (comma-separated): 2,3
Enter the minimum support (e.g., 2): 2
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from scipy.cluster.hierarchy import linkage, dendrogram as dendogram
def get_user_input():
n = int(input("Enter the number of points in the dataset: "))
X = []
print("Enter the co-ordinates (x,y) for each point: ")
for i in range(n):
while True:
try:
coords = input(f"Point {i+1}: ").split()
if len(coords) != 2:
raise ValueError("Please enter exactly two values separated by a space: ")
x, y = map(float, coords)
X.append([x, y])
break
except ValueError as e:
print(f"Invalid input: {e}. Please try again")
return np.array(X)
X = get_user_input()
print("Single Linkage Clustering:")
hierarchical_clustering_with_dendogram(X, method='single')
print("Complete Linkage Clustering:")
hierarchical_clustering_with_dendogram(X, method='complete')
print("Average Linkage Clustering:")
hierarchical_clustering_with_dendogram(X, method='average')
Output------------
Enter the number of points in the dataset: 6
Enter the co-ordinates (x,y) for each point:
Point 1: 0.4 0.53
Point 2: 0.22 0.38
Point 3: 0.35 0.32
Point 4: 0.26 0.19
Point 5: 0.08 0.41
Point 6: 0.45 0.30
data = get_user_data()
OUTPUT : -------------
Enter the number of points: 9
Enter value for point 1: 2
Enter value for point 2: 4
Enter value for point 3: 10
Enter value for point 4: 12
Enter value for point 5: 3
Enter value for point 6: 20
Enter value for point 7: 30
Enter value for point 8: 11
Enter value for point 9: 25
Cluster 1: 2.0 4.0 10.0 12.0 3.0 11.0
Cluster 2: 20.0 30.0 25.0