이것은 좀 길다.하지만 누군가가 이것을 볼 수 있는지 궁금하다. 여기에서 선형 회귀에 대한 일괄 형 그래디언트 디센트를 수행하고 있습니까? 이것은 하나의 독립 및 절편에 대한 예상 답변을 제공하지만 여러 독립 변수에 대해서는 제공하지 않습니다. 귀하의 코멘트에 구현 잘못과 기반 아무것도 x2
를 생성 할 때 유도 collinearity
에 문제가 없다Java에서의 그래디언트 하강 직선 회귀
/**
* (using Colt Matrix library)
* @param alpha Learning Rate
* @param thetas Current Thetas
* @param independent
* @param dependent
* @return new Thetas
*/
public DoubleMatrix1D descent(double alpha,
DoubleMatrix1D thetas,
DoubleMatrix2D independent,
DoubleMatrix1D dependent) {
Algebra algebra = new Algebra();
// ALPHA*(1/M) in one.
double modifier = alpha/(double)independent.rows();
//I think this can just skip the transpose of theta.
//This is the result of every Xi run through the theta (hypothesis fn)
//So each Xj feature is multiplied by its Theata, to get the results of the hypothesis
DoubleMatrix1D hypothesies = algebra.mult(independent, thetas);
//hypothesis - Y
//Now we have for each Xi, the difference between predictect by the hypothesis and the actual Yi
hypothesies.assign(dependent, Functions.minus);
//Transpose Examples(MxN) to NxM so we can matrix multiply by hypothesis Nx1
DoubleMatrix2D transposed = algebra.transpose(independent);
DoubleMatrix1D deltas = algebra.mult(transposed, hypothesies);
// Scale the deltas by 1/m and learning rate alhpa. (alpha/m)
deltas.assign(Functions.mult(modifier));
//Theta = Theta - Deltas
thetas.assign(deltas, Functions.minus);
return(thetas);
}
을 복구 할 수있는 경우
그럼 내가 잘못 아무것도 볼 수 없습니다를 참조하십시오. 나는 'Colt' 라이브러리에 익숙하지 않지만 함수 이름이 표현력이 풍부하고 의미가 명확하다고 가정합니다. 나는 여러분이 '독립'행렬의 첫번째 열에 요격의 벡터를 가진다고 가정합니다. '다중 회귀 '의 경우 어떻게 다른가? – iTech첫 번째 열은 가로 채기를위한 1입니다. 나는 그것이 정확할지도 모른다라고 생각한다. 그리고 나는 나의 테스트 데이터에서 공선 성을 경험하고있다. 나는 x1과 x2가 있고 x2는 단지 2 * x1 인 테스트 데이터를 만들었습니다. 내 종속 변수를 y = .5 * x1 + (1/3) * x2로 설정했습니다. 그것은 수렴했지만, 내가 기대하는 것은 아닙니다. – Jeremy
예를 들어, 위의 경우에 나는 Thetas .6333 (x1)과 .2666 (x2)를 얻습니다. 함수에 넣는 절편을 정확히 찾아냅니다 (예 : y = .5 * x1 + (1/3) * x2 + 10). 동일한 데이터 세트에서 WEKA를 사용하면 자동으로 동일 직감을 처리하고 1.1666 * x1을 처리합니다. – Jeremy