R - 转换为虚拟变量时内存不足

时间:2015-11-03 04:19:20

标签: r memory dummy-variable

我有一个带有分类变量的数据集,其中包含许多级别(5000左右)。 当我运行我的代码转换为虚拟变量时,它说它需要22 gig的内存和崩溃

dmy <- dummyVars(" ~ .", data = num_data)
new_data <- data.frame(predict(dmy, newdata = num_data))

在这种情况下我该怎么办?寻求云解决方案? 尝试优化功能?

1 个答案:

答案 0 :(得分:0)

是的,请尝试sparse.model.matrix

或延长内存限制

import UIKit
import AVFoundation
import MediaPlayer
import Foundation

class RadioFunctionViewController: UIViewController {

@IBOutlet var playButton: UIButton!
@IBOutlet var statusLabel: UILabel!
var player:AVPlayer = AVPlayer()
private let ObservatingKeyPath = "currentItem.status"
private let PlayerStatusObservingContext = UnsafeMutablePointer<Int>(bitPattern: 1)
private var playingState:Bool = false


override func viewDidLoad() {
    super.viewDidLoad()

    setStatus(4)
    getAudioData("http://184.107.179.162:7546/;")
    playingState = true


}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


@IBAction func buttonPressed(sender: AnyObject)
{
    toggle()
}

func getAudioData(audioURL:String)
{
    player = AVPlayer(URL: NSURL(string: audioURL)!)
    player.addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions.Initial, context: nil)
}

func setStatus(rawValue:Int)
{
    if rawValue == 1
    {
        statusLabel.textColor = UIColor.blueColor()
        statusLabel.text = "Ready for Streaming"
    }else if rawValue == 2
    {
        statusLabel.textColor = UIColor.redColor()
        statusLabel.text = "Failed"

    }else if rawValue == 0
    {
        statusLabel.textColor = UIColor.redColor()
        statusLabel.text = "Failed to load data"
    }else if rawValue == 3
    {
        statusLabel.textColor = UIColor.blueColor()
        statusLabel.text = "Streaming"
    }else if rawValue == 4
    {
        statusLabel.textColor = UIColor.purpleColor()
        statusLabel.text = "Gather data..."
    }
    print("The raw value send is: \(rawValue)")
}

func audioBackgroundPlayback()
{
    do{
        try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
    }catch {
        print("Could not play audio in the background")
    }

    if (NSClassFromString("MPNowPlayingInfoCenter") != nil)
    {
        let artWorkImage = MPMediaItemArtwork(image: UIImage(named: "ws")!)
        let songInfo2: [String:  AnyObject] = [MPMediaItemPropertyTitle: "Wide Streamings ABC Edition", MPMediaItemPropertyArtist: "Rumbera Network", MPMediaItemPropertyAlbumTitle: "107.9 FM", MPMediaItemPropertyArtwork: artWorkImage]

        MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = songInfo2
        UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
    }


}

func toggle()
{
    if playButton.titleLabel?.text == "Play"
    {
        print("The play option is chosen")
        playRadio()
    }else{
        print("The pause option is chosen")
        pauseRadio()
    }
}

func playRadio()
{
    player.play()
    setStatus(3)
    playButton.setTitle("Pause", forState: UIControlState.Normal)
    audioBackgroundPlayback()
}

func pauseRadio()
{
    player.pause()
    playButton.setTitle("Play", forState: UIControlState.Normal)
}

override func remoteControlReceivedWithEvent(event: UIEvent?) {
    if event?.type == UIEventType.RemoteControl
    {
        if event?.subtype == UIEventSubtype.RemoteControlPlay
        {
            toggle()
        }else if event?.subtype == UIEventSubtype.RemoteControlPause
        {
            pauseRadio()
        }else if event?.subtype == UIEventSubtype.RemoteControlTogglePlayPause
        {
            toggle()
        }
    }
}

override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>)
{
    if (keyPath!.containsString("status"))
    {
        if player.status == AVPlayerStatus.ReadyToPlay
        {
            player.prerollAtRate(0.001, completionHandler: {(succes:Bool)-> Void in

                if succes{
                    self.setStatus(1)
                    self.setStatus(3)
                    self.playRadio()

                }else{
                    self.setStatus(1)
                    self.setStatus(2)
                }

            })
        }else if player.status == AVPlayerStatus.Failed{
            self.setStatus(2)

        }else if player.status == AVPlayerStatus.Unknown
        {
            self.setStatus(0)
        }

    }
}

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    self.navigationController?.navigationBarHidden = false
}

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    self.navigationController?.navigationBarHidden = false
    if playingState == true
    {
        audioBackgroundPlayback()
        player.removeObserver(self, forKeyPath: "status")
        print("The AVPlayer is playing in background")
    }else{
        player.removeObserver(self, forKeyPath: "status")
        print("The view Dissapear")
    }


}