Posts

Showing posts from October, 2025

k means JDK java

import java.util.*; public class KMeansDynamic {     public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         System.out.print("Enter number of data points: ");         int n = sc.nextInt();         System.out.print("Enter number of features: ");         int f = sc.nextInt();         double[][] data = new double[n][f];         for (int i = 0; i < n; i++) {             System.out.print("Enter features for data point " + (i + 1) + " separated by space: ");             for (int j = 0; j < f; j++) {                 data[i][j] = sc.nextDouble();             }         }         System.out.print("Enter number of clusters (k): ");   ...

Chi square test

import numpy as np from scipy.stats import chi2_contingency r=int(input("Enter number of rows: ")) c=int(input("Enter number of columns: ")) observed=[] print("Enter observed values:") for i in range(r):     row=list(map(float,input(). split()))     observed.append(row) observed=np.array(observed) chi2,p,dof,expected=chi2_ contingency(observed) print("\nChi-Square Value:",chi2) print("Degrees of Freedom:",dof) print("Expected Frequencies:\n",expected) print("P-Value:",p) alpha=0.05 if p<alpha:     print("\nConclusion: Reject the Null Hypothesis (Variables are dependent)") else:     print("\nConclusion: Fail to Reject the Null Hypothesis (Variables are independent)") Output: Enter number of rows: 2 Enter number of columns: 2 Enter observed values: 50 30 20 40 Chi-Square Value: 10.529166666666667 Degrees of Freedom: 1 Expected Frequencies:  [[40. 40.]  [30. 30.]] P-Value: 0.0011750518530845063 Co...