%jars /home/vishnuaa77/vscode/vishnu/lib/commons-math3-3.6.1.jar
%jars /home/vishnuaa77/vscode/vishnu/lib/jfreechart-1.5.4.jar
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.apache.commons.math3.linear.ArrayRealVector;
import org.apache.commons.math3.linear.LUDecomposition;
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.linear.RealVector;
public class BasketballPerformanceRegression {
public static void main(String[] args) {
// Mock data for 5 basketball players
double[][] xData = {
{22, 7, 10, 35}, // Player 1: points, assists, rebounds, minutes
{15, 12, 8, 30}, // Player 2
{30, 4, 12, 40}, // Player 3
{8, 10, 5, 25}, // Player 4
{27, 3, 7, 38} // Player 5
};
double[] yData = {90, 75, 85, 65, 88}; // Performance scores for each player
double[] coefficients = calculateCoefficients(xData, yData);
System.out.println("Coefficients: " + java.util.Arrays.toString(coefficients));
}
public static double[] calculateCoefficients(double[][] xData, double[] yData) {
int n = xData.length;
int m = xData[0].length;
RealMatrix X = new Array2DRowRealMatrix(n, m + 1); // +1 for bias term
RealVector Y = new ArrayRealVector(yData, false);
for (int i = 0; i < n; i++) {
X.setEntry(i, 0, 1); // Bias term
for (int j = 0; j < m; j++) {
X.setEntry(i, j + 1, xData[i][j]);
}
}
RealMatrix Xt = X.transpose();
RealMatrix XtX = Xt.multiply(X);
RealMatrix XtXInverse = new LUDecomposition(XtX).getSolver().getInverse();
RealVector XtY = Xt.operate(Y);
RealVector B = XtXInverse.operate(XtY);
return B.toArray();
}
}
BasketballPerformanceRegression.main(null);
Coefficients: [-500.9701492539607, -18.805970149260247, -0.5970149253726049, -0.8208955223876728, 29.059701492544264]