预测函数R返回0.0

时间:2017-02-26 08:32:53

标签: java r

我试图使用线性回归预测该值。我编写了代码但是,它为预测函数抛出了0.0。此外,lm()返回多个系数对,它应该只返回一对系数。

请帮我解决。

下面是代码:

import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;

public class Prediction {


    public static void main(String[] agrs){

        String readCsv = "read.csv(\"myDatanew.csv\",stringsAsFactors=FALSE, sep=\",\")";

        Rengine engine = new Rengine(new String[] { "--no-save" }, false, null);

        engine.eval("myData="+ readCsv);        
        engine.eval("y=myData$DELTA");
        System.out.println(engine.eval("y"));
        engine.eval("x=myData$KM");
        System.out.println(engine.eval("x"));           
        engine.eval("model= lm(y ~ x)");
        System.out.println(engine.eval("model"));
        //engine.eval("predict.list = predict(model, newdata = data.frame(x =c(100)), se.fit = TRUE");
         REXP result = engine.eval("predict(model, newdata = data.frame(x =c(100)), se.fit = TRUE");
         System.out.println(result.asDouble());                                 
    }    
}

输出:

[INT* (81, 76, 18, 51, 35, 12, 37, 48, 63, 49, 33, 21, 38, 25, 71, 35, 28, 46, 17, 47, 17, 50, 38, 42, 35, 22, 27, 20, 63, 17, 24, 13, 21, 75, 80, 15, 47, 41, 31, 37, 28, 70, 82, 48, 34, 23, 32, 54, 22, 21, 28, 14, 52, 23, 60, 34, 22, 27, 66, 82, 34, 49, 13, 56, 77, 17, 32, 18, 27, 75, 12, 62, 28, 51, 15, 29, 40, 67, 21, 14, 45, 34, 37, 26, 37, 21, 23, 12, 72, 27, 33, 12, 49, 47, 25, 38, 30, 22, 15, 42, ... (92 more values follow))]
[REAL* (57.42, 84.12, 89.11, 78.47, 67.34, 85.25, 143.41, 98.21, 141.78, 59.0, 53.79, 66.81, 69.26, 93.28, 14.86, 99.49, 104.96, 91.15, 174.71, 34.98, 59.88, 48.8, 79.16, 127.71, 119.94, 101.55, 76.22, 70.0, 44.43, 87.06, 86.63, 78.31, 86.95, 52.79, 29.24, 136.47, 44.72, 74.15, 156.03, 159.68, 173.39, 61.2, 77.72, 41.83, 42.82, 141.78, 180.22, 77.39, 161.68, 156.14, 127.14, 100.86, 74.67, 191.91, 49.22, 87.68, 91.32, 88.7, 93.52, 38.56, 161.09, 100.82, 148.62, 74.95, 94.48, 63.12, 61.38, 88.78, 93.37, 38.17, 93.67, 73.11, 46.89, 27.45, 93.87, 75.07, 93.55, 34.3, 78.38, 105.93, 70.11, 70.03, 35.78, 43.73, 74.57, 73.76, 152.48, 116.75, 39.26, 58.15, 110.18, 99.58, 81.96, 48.74, 67.72, 136.5, 54.63, 65.05, 99.0, 91.33, ... (92 more values follow))]
[VECTOR ([REAL* (54.32900071718759, -0.16654601710896966)], [REAL* (36.23407158520959, 35.68085024201898, -21.488085132607292, 9.739865245353272, -8.113791925069558, -28.130952758647915, 6.555363596409759, 10.027483623084333, 32.28389358852214, 4.497214292241633, -12.3704904568961, -22.202061314137314, -4.794023572220338, -13.793588241262889, 19.145873097051712, -2.7593374750161868, -8.848330761430123, 6.851668742295009, -8.231746068079492, -1.5032210387158174, -27.356225212702473, 3.7984449177301425, -3.1452180028415384, 8.940591127798935, 0.6465285748622428, -15.41625267977171, -14.634863293141908, -22.6707795195597, 16.070638822963943, -22.82950446768068, -15.901119255037536, -28.286782117384163, -18.847824529562665, 29.462963525994937, 30.540804823078698, -16.600465762326493, 0.11893716792554783, -0.9796135485574752, 2.6571743323249564, 9.265067294772695, 2.5484131893366655, 25.863615529881365, 40.614955732521544, 0.6376191784806259, -13.197500264581494, -7.7161064114778615, 7.685922486190932, 12.559995546875586, -5.401840671009366, -7.32450560579306, -5.154340101953176, -23.5311694315769, 10.106990380339187, 0.6328454261947848, 13.86839424491591, -5.7262459370731165, -17.12001843479647, -12.556368999621968, 27.246382802843264, 34.0930137025343, 6.499897178896342, 11.462168727738742, -16.57693165445251, 14.1536232651297, 38.406266979267876, -26.816616117269415, -12.106406187039017, -21.543045318253252, -11.77859909972308, 27.028060755861798, -26.72863529459039, 19.847178593649193, -18.51965797494799, 1.242687452453641, -23.695326091168596, -12.826391212817226, 1.251379183356534, 18.383527669650082, -20.275123896186535, -22.68678112483442, 2.3475405423222866, -8.66578313904643, -11.369984225028642, -21.045943389012333, -4.9096642213717105, -21.044566495229976, -5.934064028411887, -22.88475321971537, 24.209595914510572, -17.64434982230099, -2.9789605521212996, -25.744348333476378, 8.321110845063576, 0.7884521567036052, -18.050504438568154, 6.404530618186781, -15.230591802524565, -21.495182304249102, -22.840945023399584, 2.8816470253746216, ... (92 more values follow))], [REAL* (-535.2758683224318, -94.82118244139097, -24.08092889205901, 6.534034429355505, -11.960839464691155, -30.94617716079397, 7.090827841699638, 7.958905109362791, 32.725450982104306, 0.16968629664315088, -16.998174708566474, -26.079642983455283, -8.530456906149414, -16.146191772726162, 12.275370601834553, -4.754173184942714, -10.528031208263897, 4.376352576391596, -5.893039823739669, -7.214578836780103, -31.633055030691885, -1.1167210456098557, -6.311296838668556, 8.571553795290601, -0.17015062130801145, -17.29240856484064, -17.9703201314356, -26.364580295044785, 10.903710318542533, -25.540451936335348, -18.63683969684209, -31.501830783856306, -21.565109270418468, 24.777667708859706, 24.498756639246146, -16.464825781362702, -5.031283982511056, -4.434326327363413, 3.9196965337812983, 10.737871710175757, 4.811072167262879, 21.662832978305563, 37.365916242425136, -4.679099396149407, -18.457183389401322, -7.274549017895694, 10.342068456242101, 9.291944240175775, -3.813813124676597, -6.055646132135586, -5.556216026776478, -25.447077296816577, 6.6822356155749745, 3.9624705965301033, 8.977425139071151, -8.401474235139574, -19.585540634570858, -15.172833500914274, 24.907606047091555, 28.58790530883419, 8.053933901604847, 9.543956399880472, -15.741311153090738, 10.744999738695645, 36.12279732636243, -30.906784463152697, -16.296818656831146, -24.15490089430837, -14.126017590294515, 21.5004838516304, -29.05877031552237, 16.332549786759806, -23.54486202832586, -4.902485433560999, -26.013938799007605, -16.228101351395498, -1.0856692254312286, 12.632994007069694, -23.48613975307614, -24.310598353167286, -1.3399229609616634, -12.357855567567569, -17.035252770721044, -26.253199989259144, -8.34018014268241, -24.521747784567207, -4.87606288435578, -23.885213309718512, 18.74481561663586, -22.0208476485446, -4.3579286272285325, -27.73399900251107, 5.31634439253815, -4.130170500564284, -21.875659583313105, 6.541898946114516, -19.80988233920446, -25.474160328785217, -24.864010400403888, 0.4167009412548822, ... (92 more values follow))], [INT* (2)], [REAL* (44.76592841479041, 40.31914975798102, 39.488085132607296, 41.26013475464673, 43.113791925069556, 40.130952758647915, 30.44463640359024, 37.972516376915664, 30.71610641147786, 44.50278570775836, 45.3704904568961, 43.20206131413731, 42.79402357222034, 38.79358824126289, 51.85412690294829, 37.75933747501619, 36.84833076143012, 39.14833125770499, 25.23174606807949, 48.503221038715814, 44.35622521270247, 46.201555082269856, 41.14521800284154, 33.05940887220106, 34.353471425137755, 37.41625267977171, 41.634863293141905, 42.6707795195597, 46.92936117703606, 39.82950446768068, 39.901119255037536, 41.28678211738416, 39.847824529562665, 45.53703647400506, 49.4591951769213, 31.600465762326493, 46.881062832074456, 41.979613548557474, 28.342825667675044, 27.734932705227305, 25.451586810663336, 44.136384470118635, 41.385044267478456, 47.36238082151937, 47.19750026458149, 30.71610641147786, 24.314077513809067, 41.440004453124416, 27.401840671009367, 28.32450560579306, 33.154340101953174, 37.5311694315769, 41.893009619660816, 22.367154573805216, 46.13160575508409, 39.72624593707312, 39.12001843479647, 39.55636899962197, 38.753617197156736, 47.9069862974657, 27.50010282110366, 37.53783127226126, 29.57693165445251, 41.846376734870304, 38.593733020732124, 43.81661611726942, 44.10640618703901, 39.54304531825325, 38.77859909972308, 47.9719392441382, 38.72863529459039, 42.15282140635081, 46.51965797494799, 49.757312547546356, 38.695326091168596, 41.82639121281723, 38.74862081664347, 48.61647233034992, 41.275123896186535, 36.686781124834425, 42.652459457677715, 42.66578313904643, 48.369984225028645, 47.045943389012336, 41.90966422137171, 42.04456649522997, 28.93406402841189, 34.88475321971537, 47.79040408548943, 44.64434982230099, 35.9789605521213, 37.74434833347638, 40.67888915493643, 46.211547843296394, 43.050504438568154, 31.595469381813217, 45.230591802524565, 43.4951823042491, 37.840945023399584, 39.11835297462538, ... (92 more values follow))], [INT* (0, 1)], [VECTOR ([REAL* (-13.856406460551018, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, 0.07216878364870323, ... (284 more values follow))], [REAL* (1.0721687836487033, 1.0134562738195934)], [INT* (1, 2)], [REAL* (1.0E-7)], [INT* (2)])], [INT* (190)], [VECTOR ()], [NULL ], [NULL ], [VECTOR ([REAL* (81.0, 76.0, 18.0, 51.0, 35.0, 12.0, 37.0, 48.0, 63.0, 49.0, 33.0, 21.0, 38.0, 25.0, 71.0, 35.0, 28.0, 46.0, 17.0, 47.0, 17.0, 50.0, 38.0, 42.0, 35.0, 22.0, 27.0, 20.0, 63.0, 17.0, 24.0, 13.0, 21.0, 75.0, 80.0, 15.0, 47.0, 41.0, 31.0, 37.0, 28.0, 70.0, 82.0, 48.0, 34.0, 23.0, 32.0, 54.0, 22.0, 21.0, 28.0, 14.0, 52.0, 23.0, 60.0, 34.0, 22.0, 27.0, 66.0, 82.0, 34.0, 49.0, 13.0, 56.0, 77.0, 17.0, 32.0, 18.0, 27.0, 75.0, 12.0, 62.0, 28.0, 51.0, 15.0, 29.0, 40.0, 67.0, 21.0, 14.0, 45.0, 34.0, 37.0, 26.0, 37.0, 21.0, 23.0, 12.0, 72.0, 27.0, 33.0, 12.0, 49.0, 47.0, 25.0, 38.0, 30.0, 22.0, 15.0, 42.0, ... (92 more values follow))], [REAL* (57.42, 84.12, 89.11, 78.47, 67.34, 85.25, 143.41, 98.21, 141.78, 59.0, 53.79, 66.81, 69.26, 93.28, 14.86, 99.49, 104.96, 91.15, 174.71, 34.98, 59.88, 48.8, 79.16, 127.71, 119.94, 101.55, 76.22, 70.0, 44.43, 87.06, 86.63, 78.31, 86.95, 52.79, 29.24, 136.47, 44.72, 74.15, 156.03, 159.68, 173.39, 61.2, 77.72, 41.83, 42.82, 141.78, 180.22, 77.39, 161.68, 156.14, 127.14, 100.86, 74.67, 191.91, 49.22, 87.68, 91.32, 88.7, 93.52, 38.56, 161.09, 100.82, 148.62, 74.95, 94.48, 63.12, 61.38, 88.78, 93.37, 38.17, 93.67, 73.11, 46.89, 27.45, 93.87, 75.07, 93.55, 34.3, 78.38, 105.93, 70.11, 70.03, 35.78, 43.73, 74.57, 73.76, 152.48, 116.75, 39.26, 58.15, 110.18, 99.58, 81.96, 48.74, 67.72, 136.5, 54.63, 65.05, 99.0, 91.33, ... (92 more values follow))])])]
0.0

0 个答案:

没有答案